diff --git a/_posts/2014/2014-03-17-Git_merge_--squash_and_git_rebase.md b/_posts/2014/2014-03-17-Git_merge_--squash_and_git_rebase.md new file mode 100644 index 0000000..6dab7df --- /dev/null +++ b/_posts/2014/2014-03-17-Git_merge_--squash_and_git_rebase.md @@ -0,0 +1,53 @@ +--- +layout: post-en +title: Git Cookbook +categories: +- Common Tec +tags: +- Git +--- + +> One advantage for Git comes from its powerful branch management capability, but it will be hard to maintain the commit history between different branch. As Linus said that [Clear and Clean is important for the commit history](http://blog.sevenche.com/2014/02/Linus-Torvalds-rules-for-using-Git/). Here in this article I am going to demonstrate how `git merge --squash`, `git merge`, and `git rebase` will affect the commit history. + +### `git merge` and `git merge --squash` + +In below example I am going to merge `dev3` into `dev2` and `dev4` by using merge with and without `--squash` parameter. +Initial status: +![](/media/pic2014/0317-2.png) + +**merge with `--squash` test** +``` +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 `fbcb87a` and `b85fcb7` in the history of `dev4` + +**Plain merge ** + +``` +git checkout dev2 +git merge dev3 +``` +![](/media/pic2014/0317-3.png) +Now `dev4` and `dev2` have the same content, but we cannot see `dev4` comes contains commit form `dev3`, but `dev2` has the information. + +** Conclusion ** +`--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! + +### Rebase + +** Before rebase ** +![](/media/pic2014/0317-0.png) + +** rebase ** +``` +git checkout dev +git rebase master +``` +** After rebase ** +> Notice: dev commit ccd4673 changed to 9d76e0b +![](/media/pic2014/0317-1.png) + +** Conclusion** +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. \ No newline at end of file diff --git a/media/pic2014/0317-0.png b/media/pic2014/0317-0.png new file mode 100644 index 0000000..1ffcc72 Binary files /dev/null and b/media/pic2014/0317-0.png differ diff --git a/media/pic2014/0317-1.png b/media/pic2014/0317-1.png new file mode 100644 index 0000000..5ddda16 Binary files /dev/null and b/media/pic2014/0317-1.png differ diff --git a/media/pic2014/0317-2.png b/media/pic2014/0317-2.png new file mode 100644 index 0000000..f4cab9c Binary files /dev/null and b/media/pic2014/0317-2.png differ diff --git a/media/pic2014/0317-3.png b/media/pic2014/0317-3.png new file mode 100644 index 0000000..4adb57e Binary files /dev/null and b/media/pic2014/0317-3.png differ diff --git a/media/pic2014/0317-4.png b/media/pic2014/0317-4.png new file mode 100644 index 0000000..ed562ae Binary files /dev/null and b/media/pic2014/0317-4.png differ