Git Good
Tips and tricks for using Git.
Splitting a commit in two¶
Problem¶
Have:
a2c
a --> c
^
YOU ARE HEREWant:
a2b a2c
a --> b --> cSolution¶
Commit
c2b:a2c c2b a --> c --> b ^ YOU ARE NOW HERERecord its hash using
C2B_HASH=$(git rev-parse HEAD).Squash
c2bintoa2c:git reset --soft HEAD~2 git commit -m "a2b"This can also be achieved using an interactive rebase (
git rebase -i HEAD~2).Create new commit
b2c:git revert --no-commit $C2B_HASH git commit -m "b2c"