[英]Differences between Git merge --squash and --no-commit
As the title says, I am not really clear about the differences between a git merge --squash
and a git merge --no-commit
.正如标题所说,我不太清楚
git merge --squash
和git merge --no-commit
之间的区别。
As far as I understand the help page for git merge
, both commands would leave me in an updated working-tree, where it is still possible to edit and then to do a final commit (or multiple commits).据我了解
git merge
的帮助页面,这两个命令都会将我留在更新的工作树中,在那里仍然可以编辑然后进行最终提交(或多次提交)。
Could someone clarify the differences of those 2 options?有人可以澄清这两个选项的区别吗? When would I use one instead of the other?
我什么时候用一个代替另一个?
git merge --no-commit
This is just like a normal merge but doesn't create a merge-commit. 这与普通合并类似,但不会创建合并提交。 This commit will be a merge commit: when you look at the history, your commit will appear as a normal merge.
此提交将是合并提交:当您查看历史记录时,您的提交将显示为正常合并。
git merge --squash
This will merge the changes into your working tree without creating a merge commit. 这会将更改合并到您的工作树中,而不会创建合并提交。 When you commit the merged changes, it will look like a new "normal" commit on your branch: without a merge commit in the history.
当您提交合并的更改时,它将看起来像您的分支上的新“正常”提交:在历史记录中没有合并提交。 It's almost like you did a cherry-pick on all the merged changes.
这几乎就像你对所有合并的变化做了一个挑选。
Basically, there's no such difference at the very end, however looking at the sketch here below, once you checkout master
branch基本上,最后没有这样的区别,但是看看下面的草图,一旦你
checkout master
分支
A---B---C topic
/ \
D---E---F---G---H master (from the documentation https://git-scm.com/docs/git-merge)
git merge topic
: incorporates/replay changes from the named branch (since its history diverged from the current branch) into the current branch and record the result in a new commit H
along with the names of the two parent commits and a log message from the user describing the changes. git merge topic
:将命名分支的更改(因为其历史与当前分支不同)合并/重放到当前分支中,并将结果H
两个父提交的名称和来自描述更改的用户。 Then it's up to you to push it upstream, as usual.$ git log --all --decorate --oneline --graph
* 72e576d (HEAD -> master) H Merge branch 'topic'
|\
| * dda0d97 (topic) C
| * 3471c39 B
| * cfb8410 A
* | a1c7e23 G
* | 5c0b97b F
|/
* c463d89 E
* 2312a5b D
$ git show HEAD -m
commit 72e576d (from a1c7e23) (HEAD -> master)
Merge: a1c7e23 dda0d97
H Merge branch 'topic'
diff --git a/A b/A
diff --git a/B b/B
diff --git a/C b/C
commit 72e576d (from dda0d97) (HEAD -> master)
Merge: a1c7e23 dda0d97
H Merge branch 'topic'
diff --git a/F b/F
diff --git a/G b/G
git merge --no-commit
: the same as above, but stop just before creating a new commit , to give the user a chance to inspect and further tweak the merge result before committing. git merge --no-commit
:与上面相同,但在创建新提交之前停止,让用户有机会在提交之前检查并进一步调整合并结果。 Then it's up to you to commit what has been added to the index and push it upstream, as usual.$ git log --all --decorate --oneline --graph
* f576f37 (HEAD -> master) H
|\
| * dda0d97 (topic) C
| * 3471c39 B
| * cfb8410 A
* | a1c7e23 G
* | 5c0b97b F
|/
* c463d89 E
* 2312a5b D
$ git show HEAD -m
commit f576f37 (from a1c7e23 ) (HEAD -> master)
Merge: a1c7e23 dda0d97
H
diff --git a/A b/A
diff --git a/B b/B
diff --git a/C b/C
commit f576f37 (from dda0d97) (HEAD -> master)
Merge: a1c7e23 dda0d97
H
diff --git a/F b/F
diff --git a/G b/G
git merge --squash
: working tree and index state are as if a real merge happened ( except for the merge information ), without committing it, thus allowing to create a single commit on top of the current branch. git merge --squash
:工作树和索引 state 就像发生了真正的合并(合并信息除外),没有提交它,因此允许在当前分支的顶部创建单个提交。 Again, it's up to you to commit and push upstream, as before.$ git log --all --decorate --oneline --graph
* 118019a (HEAD -> master) H
* a1c7e23 G
* 5c0b97b F
| * dda0d97 (topic) C
| * 3471c39 B
| * cfb8410 A
|/
* c463d89 E
* 2312a5b D
$ git show HEAD -m
commit 118019a (HEAD -> master)
H
diff --git a/A b/A
diff --git a/B b/B
diff --git a/C b/C
NOTE: fast-forward updates do not create a merge commit, thus, to ensure your branch is not changed/updated use --no-ff
with --no-commit
option.注意:快进更新不会创建合并提交,因此,要确保您的分支不会更改/更新,请使用
--no-ff
和--no-commit
选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.