mirror of
https://gh-proxy.org/https://github.com/klinsmaya/dashjim.github.com.git
synced 2026-11-08 01:16:54 +08:00
add post 03-17
This commit is contained in:
@@ -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:
|
||||

|
||||
|
||||
**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
|
||||
```
|
||||

|
||||
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 **
|
||||

|
||||
|
||||
** rebase **
|
||||
```
|
||||
git checkout dev
|
||||
git rebase master
|
||||
```
|
||||
** After rebase **
|
||||
> Notice: dev commit ccd4673 changed to 9d76e0b
|
||||

|
||||
|
||||
** 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.
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 8.6 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 9.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.5 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 4.5 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 4.8 KiB |
Reference in New Issue
Block a user