默认的 Git 分歧合并策略是什么/曾经是什么?

3

我最近开始使用一台新机器,在尝试推送到一个分支时注意到这个错误提示。这是因为之前我在GitHub上解决了一些问题并忘记了进行拉取。

所以我进行了拉取,通常情况下,在进行拉取操作时,我会得到一个文件列表,需要解决它们的更改,添加它们,然后推送。

然而今天遇到了不同的情况。我得到了这条信息:

hint: You have divergent branches and need to specify how to reconcile them.
hint: You can do so by running one of the following commands sometime before
hint: your next pull:
hint:
hint:   git config pull.rebase false  # merge
hint:   git config pull.rebase true   # rebase
hint:   git config pull.ff only       # fast-forward only
hint:
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.

fatal: Need to specify how to reconcile divergent branches.

每当设置新的机器时,我以前从未见过这种情况。我在其他两台机器上使用相同的`.gitconfig`,但没有看到这条消息。
[user]
  name = my name
  email = my email 

[format]
  numbered = auto

[color]
  branch = yes
  diff   = auto
  pager  = yes
  status = auto

我已经做过这个很多次,但突然间我忘了。我从未在 Git 中记得见过这个提示或错误(6年来)。这是新的吗?也许我可以查看 Git 源代码的历史记录?如果不是,那么默认是什么?


1
它是在最近的Git版本中引入的。也许你使用的是旧版本,所以你以前从未见过这个提示。 - ElpieKay
3个回答

2

确实是新的功能(部分在Git 2.27中引入,修复在2.29中):现在可以和应该配置pull.rebasepull.ff到一些设置。

以前的默认默认值相当于pull.rebase falsepull.ff true。这使得git pull运行git merge,如果可能的话,进行快进非合并“虚假”合并,如果不可能,则进行真正的合并。

pull.ff配置为only会使git pull作为其第二个命令运行等效于git merge --ff-only(前提是你没有进行变基)。这是我的一般个人偏好,但我并不是在所有地方都使用Git 2.29或更高版本,所以我仍然使用自己的运行git fetch,然后查看,然后决定,也许使用我的git mff别名来执行只快进合并的过程。


1

如果有所帮助,可以尝试以下替代方法:

我曾遇到过这个问题。但是以下建议对我没有起作用。

- git config pull.rebase false  
- git config pull.rebase true   
- git config pull.ff only 

OR even adding 'git config --global pull.ff only' not worked

最终我用另一种方法解决了这个问题。

步骤:

- Create a new branch   // git create branch new_branch
- switch to new branch      // git checkout new_branch
- merge prev_branch to new_branch   // git merge origin prev_branch

1

问题简述:

Git 强制我们选择它应该如何处理远程分支(例如 origin/develop)和本地分支(develop)之间的不同步,因此它很容易修改行为并添加此消息以提醒您可能需要更改默认设置。

要解决此问题,我们需要运行以下命令来更改默认设置:

git pull --ff-only

或者更好地作为全局默认值使用,带有HTML标签。
git config --global pull.ff only

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接