在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 rebase /my_remote_branch_name

其他回答

在我的例子中,当我只想获得我想要的分支的最新更新时,我正在从一个不同的分支进行拉取。我把树枝换回去,它就恢复正常了。

对我来说,一旦我设置了配置,我仍然无法合并。 这是致命的:不可能快进,中止

上述解决方案都不起作用,所以我使用了合并和develop。合并起源/开发

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

但它们都是有效的。

这对我来说很管用:

git rebase /my_remote_branch_name