在git拉origin master之后,我得到了以下消息:

warning: Pulling without specifying how to reconcile divergent branches is
discouraged. You can squelch this message by running one of the following
commands sometime before your next pull:

  git config pull.rebase false  # merge (the default strategy)
  git config pull.rebase true   # rebase
  git config pull.ff only       # fast-forward only

You can replace "git config" with "git config --global" to set a default
preference for all repositories. You can also pass --rebase, --no-rebase,
or --ff-only on the command line to override the configured default per
invocation.

remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), 51.49 KiB | 850.00 KiB/s, done.

拉动似乎成功了,但我不确定。

我该怎么补救呢?


当前回答

Git配置拉。仅Ff或等价于git pull, Ff -only是最安全的。原因是,如果另一个开发人员强制推送到同一个分支,那么rebase可能会覆盖历史记录,并可能导致提交丢失。

但它们都是有效的。

其他回答

我不知道这是否与您的问题有关,但请注意Git v2.34.0版本有一个问题。git pull命令没有预期的行为。

发布说明中关于Git修复和2021-11-24新版本的消息:

当对方在我们身后的时候,任何策略都应该是“git pull” 成功,因为它是一个没有操作,但没有”。

Git v2.34.1版本说明

确保您当前所在的分支存在于远程存储库中。如果你正在使用Atlassian (Bitbucket和Jira),可能是在一个pull请求后,你的分支被删除了,你忘记签出到其他分支(即master/develop)。

Git配置拉。仅Ff或等价于git pull, Ff -only是最安全的。原因是,如果另一个开发人员强制推送到同一个分支,那么rebase可能会覆盖历史记录,并可能导致提交丢失。

但它们都是有效的。

注意:之前我们教过“git pull”(man),当用户没有说历史需要合并、重基或只接受快进时,它会发出警告,但对那些设置了pull的人会触发警告。Ff配置变量。

Git 2.29 (Q4 2020)不再是这种情况(意味着:不再有警告)。

参见Alex Henrie提交54200ce(2020年9月24日)。 (由Junio C Hamano—gitster—在commit 299dea中合并,2020年9月29日)

拉:如果拉,不要警告。Ff已经被设定 署名:Alex Henrie

一个足够理解设置拉的用户。Ff不需要额外的指令。


在Git 2.31 (Q1 2021)之前,当用户没有告诉“Git pull”(man)使用rebase或merge时,该命令会给出一个响亮的消息,告诉用户在rebase或merge之间进行选择,但还是会创建merge,迫使想要rebase的用户重做操作。

通过收紧条件来给出消息来修复这个问题的早期部分——如果历史快进,没有理由停止或强迫用户在rebase或merge之间进行选择。

参见Junio C Hamano (gitster) commit 7539fdc, commit b044db9(2020年12月14日)。 参见Felipe Contreras (felipec)的commit c525de3, commit 278f4be, commit 77a7ec6(2020年12月12日)。 (由Junio C Hamano—gitster—在commit d3fa84d中合并,2021年1月6日)

Pull:仅在非ff时显示默认警告 建议:滨野Junio C 署名:费利佩·孔特雷拉斯

没有必要在每次拉动时都显示恼人的警告…只有那些不是快进的。 当前的警告测试仍然通过,但不是因为参数或配置,而是因为它们都是快进的。 我们现在需要测试非快进的情况。


在2.34(2021年第四季度)中,警告发生了变化:“git pull”(man)有各种角落的情况,这些情况在其-rebase后端周围没有得到很好的考虑,例如。“git pull -ff-only”(男人)没有停下来,而是继续前进,当另一边的历史不是我们历史的后代时。

参见下面:Git 2.34还没有修复所有问题。

参见Elijah Newren (Newren)的commit 6f843a3, commit 359ff69, commit 031e2f7, commit adc27d6, commit e4dc25e(2021年7月22日)和commit 1d25e5b, commit be19c5c(2021年7月21日)。 参见Alex Henrie (alexhenrie)提交3d5fc24(2021年7月21日)。 (由Junio C Hamano—gitster—在commit 7d0daf3中合并,2021年8月30日)

Pull:当不支持快进时,默认为中止 Initial-patch-by: Alex Henrie 署名:以利亚·纽伦

当用户没有指定如何用git pull协调发散的分支时,我们已经给出了很长的警告。 现在让它成为一个错误。

Git pull现在包含在它的手册页中:

Incorporates changes from a remote repository into the current branch. If the current branch is behind the remote, then by default it will fast-forward the current branch to match the remote. If the current branch and the remote have diverged, the user needs to specify how to reconcile the divergent branches with --no-ff, --ff, or --rebase (or the corresponding configuration options in pull.ff or pull.rebase). More precisely, git pull runs git fetch with the given parameters and then depending on configuration options or command line flags, will call either git merge or git rebase to reconcile diverging branches.

所以:而不是看到(在Git 2.33.1之前):

不鼓励在没有说明如何协调不同分支的情况下进行拉。 你可以在下次拉之前通过运行以下命令之一来压制此消息: Git配置拉。Rebase false # merge(默认策略) Git配置拉。Rebase true # Rebase

你会看到:

您有不同的分支,需要指定如何协调它们。 你可以在下次拉之前运行以下命令: Git配置拉。Rebase false # merge(默认策略) Git配置拉。Rebase true # Rebase

这意味着,如果你不运行这些命令之一,你将得到一个致命的错误:

致命的:需要指定如何调和不同的分支。


Git 2.35更新(2022年第一季度)

Ark Kun报道:

Git 2.34仍然是坏的。它拒绝拉取作为当前分支头祖先的远程分支。 Git失败了,而不是什么都不做。 VSCode有同步功能,可以进行拉和推操作。 由于GIT改变了行为,该特性已经被破坏了几个月。 幸运的是,这个问题最终在GIT master中得到了解决

这个问题已经在Git邮件线程中报告/讨论过了,修复正在进行中(Git commit ea1954a)

在Git 2.35 (Q1 2022)之前,当对方在我们后面时,任何策略的“Git pull”(man)都应该成功,因为这是一个没有操作的操作,但没有。

参见Erwin Villejo (erwinv)的commit ea1954a(2021年11月17日)。 (由Junio C Hamano合并- gitster -在提交0f2140f, 2021年11月21日)

Pull:当已经是最新的时候应该是noop 签字人:Erwin Villejo

已经更新的pull错误被修复了——ff-only,但它不包括没有指定——ff或——ff-only的情况。 这将更新——ff-only修复,以包括在命令行标志或配置中未指定——ff或——ff-only的情况。

此问题在2.34.1中修复,更新Git版本。