Last Updated: February 25, 2016
·
2.183K
· sheerun

Better commit history on pull and merge

Is your develop repository garbaged with Merge branch 'develop' of github.com:your/repository into develop commits? Always use the --rebase flag that prevents unnecessary merge on pull-push:

git pull --rebase origin develop

On the other hand, if you want to merge feature branch, use -no-ff flag to prevent fast-forwarding history and get real merge commit:

git merge --no-ff feature-awesome
git log --oneline

936bf9 Merge branch 'feature-awesome'
adb1b9 awesome feature
9034fd init

Now suppose you've changed your mind. Thanks to --no-ff, reverting all commits from feature is as simple as:

git revert 936bf9 -m 1
git log --oneline

15e772 Revert "Merge branch 'feature-awesome'"
936bf9 Merge branch 'feature-awesome'
adb1b9 awesome feature
9034fd init

If you want to merge feature again, you have to revert the revert commit and then merge fixed feature branch one more time:

git revert 15e772
git merge feature-awesome
git log --oneline -n4

e074bc Merge branch 'feature-awesome'
f43699 Revert "Revert "Merge branch 'feature-awesome'""
3243b5 fix
15e772 Revert "Merge branch 'feature-awesome'"

Bonus: Check out git up!