Rebasing
Rule of Thumb
Always branch off before doing large rebase
This allows you to hard reset to the original branch when a rebase goes wrong.
Incrementally squash/rebase instead of doing it all at once
Isolate the commits that are troublesome while rebasing.
Rebasing
# start interactive rebasing git rebase -i HEAD~n # abort rebasing using Vim error :cq # resolve conflict and continue rebasing git add <file> git rebase --continue # Squashing using Interactive Rebase ## first commit always needs to start as `pick` p s s s ... # Below example will fold 4 commits into the first commit: pick a1b2c3d Commit message 1 squash d4e5f6g Commit message 2 squash h7i8j9k Commit message 3 squash l0m1n2o Commit message 4
Cleaning up commit
Always prefer squash
over deletion
of commit
- IF you accidentally chose HEAD position that includes commit you don't want to squash
- Simply remove the commit from the list