This is a perfect use case for git reset --soft
.
Assume you have a commit history
D Your latest patch
C Your second patch
B Your first patch
A Someone else's work
you have no staged changes, and git status
, git log
or git show
tell you are currently at commit D.
Then git reset --soft B
will take the cumulative changes of commits C
and D
and stage them for commit. git commit --amend
will then 'merge' these changes into commit B.
Use as follows:
git reset --soft B
git commit --amend
The second command will bring up your editor with a chance to edit the commit message.
Note that if you have staged changes before starting this process (i.e. you have done git add XXX
but not followed up with a git commit
) then those staged changes will also be merged into the commit.