Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
375 views
in Technique[技术] by (71.8m points)

git - git merge和git merge --no-ff有什么区别?(What is the difference between `git merge` and `git merge --no-ff`?)

Using gitk log , I could not spot a difference between the two.

(使用gitk log ,我无法发现两者之间的差异。)

How can I observe the difference (with a git command or some tool)?

(如何观察差异(使用git命令或某些工具)?)

  ask by user1162226 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 ,然后,如果出错,则可以返回并确定是否要合并或重新设置基础。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...