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

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

我该怎么补救呢?


当前回答

哇,这里有很多好答案。 但我想从路线原因的角度来回答…

不容易确定OP路径,因为每个人都可能不同。 解决问题很好,但首先预防问题就更好了。 尽管我尊重上面的答案,因为他们的知识远比我多。

这是我的问题的原因,与上面的错误相同:

做一个提交和推拉从我的开发分支到我的远程开发分支(使用VS Code); 然后是我团队分公司的公关。 然后在github中,我将我的团队分支合并到我的开发分支中(更高),以使开发与其他团队保持一致,以确保我们所有人都一致。 第二天早上,我做了一个新的提交,但是当我在我的本地上使用Push/Pull in VS Oce时,我得到了错误。

我应该做的是我在远程合并后,我应该拉或获取远程到我的本地之前做进一步的改变,然后我就不会得到错误。

所以我的日常生活应该改变,当我合并团队到Dev在我的遥控器上,我也必须把它拉到本地直接

我还有另一个复合因素,我的新提交与合并到我的Dev分支的冲突,所以我收到了不同的错误,告诉我在Pull之前删除或隐藏我的更改。

所以,如果把这个问题解决了,按正确的顺序来做也许就能在一开始就避免这个错误。(可能)。

其他回答

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

但它们都是有效的。

我一直在用——ff-only得到错误,所以我只是创建了一个与远程分支同步的新分支:

跳到另一根树枝上:

git checkout -b other-branch

更改它的名称,这样它就不会打扰你:

git branch -m myBranch broken-myBranch

签出你想要同步的远程分支:

git checkout origin/myBranch

为它创建一个本地分支:

git checkout -b myBranch

将远程分支连接到您的:

--set-upstream-to=origin/myBranch myBranch

在默认模式下,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 reset --hard origin/<remote_branch_name>

这是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已经是最新的,或者合并可以作为快进解决