`git merge` 和 `git merge --no-ff` 有什么区别? [英] What is the difference between `git merge` and `git merge --no-ff`?
问题描述
使用 gitk log
,我无法发现两者之间的区别.如何观察差异(使用 git 命令或某些工具)?
Using gitk log
, I could not spot a difference between the two. How can I observe the difference (with a git command or some tool)?
推荐答案
--no-ff
标志阻止 git merge
执行快进",如果它检测到您当前的 HEAD
是您尝试合并的提交的祖先.快进是指 git 不构建合并提交,而是将分支指针移动到指向传入提交的位置.这通常发生在没有任何本地更改的 git pull
时.
The --no-ff
flag prevents git merge
from executing a "fast-forward" if it detects that your current HEAD
is an ancestor of the commit you're trying to merge. A fast-forward is when, instead of constructing a merge commit, git just moves your branch pointer to point at the incoming commit. This commonly occurs when doing a git pull
without any local changes.
但是,有时您希望防止这种行为发生,通常是因为您想维护特定的分支拓扑(例如,您正在合并一个主题分支,并且希望确保它在阅读历史记录时看起来是这样).为此,您可以传递 --no-ff
标志,git merge
将总是构造一个合并而不是快进.
However, occasionally you want to prevent this behavior from happening, typically because you want to maintain a specific branch topology (e.g. you're merging in a topic branch and you want to ensure it looks that way when reading history). In order to do that, you can pass the --no-ff
flag and git merge
will always construct a merge instead of fast-forwarding.
同样,如果你想执行一个 git pull
或使用 git merge
来显式快进,如果不能,你想退出快进,然后您可以使用 --ff-only
标志.通过这种方式,您可以不假思索地定期执行诸如 git pull --ff-only
之类的操作,然后如果出现错误,您可以返回并决定是否要合并或变基.
Similarly, if you want to execute a git pull
or use git merge
in order to explicitly fast-forward, and you want to bail out if it can't fast-forward, then you can use the --ff-only
flag. This way you can regularly do something like git pull --ff-only
without thinking, and then if it errors out you can go back and decide if you want to merge or rebase.
这篇关于`git merge` 和 `git merge --no-ff` 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!