One advantage for Git comes from its powerful branch management capability, but it will be hard to maintain the commit history between different branches. As Linus said that Clear and Clean is important for the commit history, here in this article I am going to demonstrate how
git merge --squash,
git merge, and
git rebasewill affect the commit history.
git merge and
git merge --squash
In below example I am going to merge
dev4 by using merge with and without
git checkout dev4 git merge --squash dev3 git commit -a
We can see changed files in working directory and after commit we don't see
b85fcb7 in the history of
git checkout dev2 git merge dev3
dev2 have the same content, but we cannot see
dev4 contains commits form
dev2 has the information.
--squash will abandon the merge history, so you will not know what was merged. Only use it when you don't want these commit history!
git rebase acts like automatically
cherrypick commits into current branch and then reapply the commits in current branch. See below example.
git checkout dev git rebase master
Notice: dev commit ccd4673 changed to 9d76e0b
Rebase do not like merge - which will cause a commit, and from the tree you cannot see when the dev is split out and when it is merged back. - So Linus calls it is a clean for history.