git pull --rebase 和 git pull --ff-only 的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25430600/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 02:21:12  来源:igfitidea点击:

Difference between git pull --rebase and git pull --ff-only

gitgit-rebasegit-pull

提问by Nico

Let's say origin/masterhas commit A--B--Cand my local/masterhas commit A--B--D.

假设origin/masterhas commitA--B--C和 my local/masterhas commit A--B--D

What will happen if I use git pull --rebase?

如果我使用会发生什么git pull --rebase

What will happen if I use git pull --ff-only?

如果我使用会发生什么git pull --ff-only

Is there any difference in the resulting commit tree ?

结果提交树有什么不同吗?

回答by Gabriele Petronella

What will happen if I use git pull --rebase ?

如果我使用 git pull --rebase 会发生什么?

git pull --rebaseis roughly equivalent to

git pull --rebase大致相当于

git fetch
git rebase origin/master

i.e. your remote changes (C) will be applied before the local changes (D), resulting in the following tree

即您的远程更改 ( C) 将在本地更改 ( D)之前应用,导致以下树

A -- B -- C -- D


What will happen if I use git pull --ff-only ?

如果我使用 git pull --ff-only 会发生什么?

It will fail.

它会失败。

git pull --ff-onlycorresponds to

git pull --ff-only对应于

git fetch
git merge --ff-only origin/master

--ff-onlyapplies the remote changes only if they can be fast-forwarded. From the man:

--ff-only仅当可以快进时才应用远程更改。来自男人:

Refuse to merge and exit with a non-zero status unless the current HEAD is already up-to-date or the merge can be resolved as a fast-forward

拒绝合并并以非零状态退出,除非当前 HEAD 已经是最新的或者合并可以解决为快进

Since your local and remote branches have diverged, they cannot be resolved by a fast-forward and git pull --ff-onlywould fail.

由于您的本地和远程分支出现分歧,因此无法通过快进解决它们并且git pull --ff-only会失败。