Move some changes from a Git commit into a separate commit -
i'm on feature branch single commit (as result of interactive rebase squashed of commits).
i've decided, prior pushing origin , creating pull request i'd take subset of changes (at file level) in commit , make second commit out of them since they're logically separate issues. how can this?
the change i'd break out never in it's own commit, got bundled first commit did part of work on feature branch.
move changes git commit separate commit
in nutshell: reset last commit , make 2 new commits
if understand correctly, want keep of changes in original commit, , put smaller subset of changes in second commit. if case, first want soft reset last commit (thanks @hvd tip):
git reset --soft head^
this remove last commit, not changes, if commit never happened, , changes staged. @ point, want unstage files don't want in first commit. can unstage file file or directory directory, this:
git reset -- path/to/file-or-dir
now can commit majority of changes (already staged), , second commit rest.
if have files want of changes in first commit , other changes in second commit, can reset entire file first, , stage changes selectively using git add -p
, this:
git reset -- path/to/file git add -p path/to/file
the -p
option of git add
let select hunks stage. note can split hunks , have fine control of lines stage.
after first commit, can proceed adding still pending (not staged) changes.
Comments
Post a Comment