git rebase --interactive
helps you.
First, stash your uncommitted changes for later use (git stash
). Your working directory should be clean now. Run git rebase -i HEAD~3
and your editor will pop up with the following content:
pick aaaaaaa
pick bbbbbbb
pick ccccccc
In the above example, bbbbbbb
should be your "commit 1" and ccccccc
should be your "commit 2". Change pick
into edit
for bbbbbbb
and exit the editor. You can then git stash pop
the changes onto the working tree, which should be at commit 1 now. Amend commit 1 with git commit --amend
and continue the rebase with git rebase --confinue
. Assume conflicts are handled, you should now land on a new HEAD with a modified commit 1' and an identical commit 2'.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…