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.
(如果--no-ff
标志检测到您当前的HEAD
是您要合并的提交的祖先,则可以防止git merge
执行“快进”。)
A fast-forward is when, instead of constructing a merge commit, git just moves your branch pointer to point at the incoming commit. (快进是指git只是移动分支指针以指向传入的提交,而不是构造合并提交。)
This commonly occurs when doing a git pull
without any local changes. (当执行git pull
而没有任何本地更改时,通常会发生这种情况。)
However, occasionally you want to prevent this behavior from happening, typically because you want to maintain a specific branch topology (eg 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. (为此,您可以传递--no-ff
标志,并且git merge
将始终构造一个合并,而不是快速转发。)
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.
(同样,如果您要执行git pull
或使用git merge
以便显式快进,并且如果无法进行快进--ff-only
纾困,则可以使用--ff-only
标志。)
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 pull --ff-only
,然后,如果出错,则可以返回并确定是否要合并或重新设置基础。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…