在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.

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

我该怎么补救呢?


当前回答

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

其他回答

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

但它们都是有效的。

在默认模式下,git pull是git fetch的简写,后面跟着git merge FETCH_HEAD。

当你做git pull origin master时, Git pull执行合并,这通常会创建合并提交。因此,默认情况下,从远程拉取不是一个无害的操作:它可以创建一个以前不存在的新的提交SHA哈希值。这种行为会使用户感到困惑,因为看似无害的下载操作实际上会以不可预知的方式更改提交历史。

为了避免这种情况,你需要

git pull --ff-only

(或不呢?往下读,看看哪一个符合你的要求)

使用git pull——ff-only, git只会在不创建新提交的情况下“快进”更新你的分支。如果不能做到这一点,git pull——ff-only会简单地中止并给出错误消息。

你可以配置你的Git客户端默认总是使用——ff-only,所以即使你忘记命令行标志,你也会得到这个行为:

git config --global pull.ff only

注意:——global标志将更改应用于您机器上的所有存储库。如果您希望此行为仅用于您所在的存储库,请省略该标志。

从这里开始



此警告是在Git 2.27中添加的。

这是完整的警告:

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.

警告显示了三个命令作为选项,所有这些都将取消警告。但它们有不同的用途:

git config pull.rebase false     # merge (the default strategy)

这将保持默认行为并抑制警告。

git config pull.rebase true      # rebase

这实际上是在远程分支上提交的,在本地和远程维护一个分支(不像默认行为,其中涉及两个不同的分支——一个在本地,另一个在远程——并且,要将两者结合起来,将执行merge)。

git config pull.ff only          # fast-forward only

这只在本地分支可以快进的情况下执行拉取。如果不是,它将简单地终止并输出错误消息(并且不创建任何提交)。


更新:

如果你有Git 2.29或更高版本,你现在可以设置pull。Ff为假,为真或只消除警告。

git config pull.ff true

true -这是默认行为。如果可能,Pull是快进的,否则是合并的。

git config pull.ff false

false - Pull从不快进,并且总是创建merge。

git config pull.ff only

only -如果可能的话,Pull是快进的,否则操作将被终止并返回错误消息。


注意:您可能需要关注VonC在这里的回答,以了解在未来的更新中对该功能所做的更改的更新。

这是Git 2.27中添加的一个新警告:

 * "git pull" issues a warning message until the pull.rebase
   configuration variable is explicitly given, which some existing
   users may find annoying---those who prefer not to rebase need to
   set the variable to false to squelch the warning.

要删除警告,如果你没有在命令行上指定行为(使用——ff,——no-ff,——ff-only,——rebase),将建议值之一设置为git拉取的首选默认行为。在所有情况下,如果可能的话,git都会尝试快进(什么是git快进?)这些设置控制在您的分支中发生更改但未在远程分支中显示时发生的情况。

  git config pull.rebase false  # merge (the default strategy)

这是现有的默认行为;设定为不发出警告,也不改变行为;Git会将远程分支合并到本地分支中。

  git config pull.rebase true   # rebase

在这里,git将尝试在远程分支的顶部重新基于您的更改。什么时候我应该使用git pull -rebase?关于你为什么想要那样做的更多细节。

  git config pull.ff only       # fast-forward only

如果快进合并是不可能的,git将拒绝继续。git pull -rebase和git pull -ff-only引号的区别:

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

如果你从一个分叉回购,像我一样:P,试试这个

git push -f origin <branch_name>

这个被推了。如果有任何冲突,您可以从git中处理

该问题将通过以下命令解决

Git配置-全局拉。Ff true在项目目录终端执行此命令。

这是一个理想的解决方案,通过桌面,但同时。对于不熟悉CLI (Command Line Interface)的用户,可以参考本手册。

从GitHub桌面,您可以按Ctrl + '(也可从 “存储库”主菜单为“在[您设置的终端]中打开”)。这 应该打开一个CLI。 从SourceTree -> Actions ->打开终端。这个会打开 终端与您的项目目录。

在终端输入: Git配置-全局拉。Ff为真(或错误提示中指定的任何其他选项)。

现在,当你试图拉它将使用该配置,并允许你继续。

我建议拉。Ff为真,因为它试图在应用本地提交之前快进您的分支,使其与远程更新,如果没有,它将执行从远程到本地分支的合并。点击这里阅读文档。

通常情况下,当您拖动一个分支、添加提交和推送时。这是在顺序假设您的本地是最新的远程。当无法快速转发时,通过合并,您将看到一个合并提交通知您它是如何处理的。(其他的选择是rebase或总是合并,许多新用户发现rebase不太直观,但实际上完成了同样的事情)

我添加了——global标志,这样你的选择将适用于你所有的回购,你不会再看到这个错误消息。如果您希望每个存储库都有不同的行为,可以忽略这个选项。