如何处理这个git警告?“不建议在不指定如何协调分歧分支的情况下进行拉动". [英] How to deal with this git warning? "Pulling without specifying how to reconcile divergent branches is discouraged"

查看:4903
本文介绍了如何处理这个git警告?“不建议在不指定如何协调分歧分支的情况下进行拉动".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

git pull origin master 之后,我收到以下消息:

After a git pull origin master I get the following message:

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.

然后,拉取已成功完成.但是,我对此消息还是有疑问.
在这种情况下最好的办法是什么?

Then the pull has been done successfully. But still, I have doubts about this message.
What is the best thing to do in this case?

推荐答案

在默认模式下,git pull是git fetch的缩写,后跟git merge FETCH_HEAD.

In its default mode, git pull is shorthand for git fetch followed by git merge FETCH_HEAD.

当您执行 git pull origin master 时,
git pull 执行合并,通常会创建合并提交.因此,默认情况下,从远程进行拉动并不是一项无害的操作:它可以创建以前不存在的新提交sha.这种行为可能会使用户感到困惑,因为看起来应该是无害的下载操作实际上会以不可预测的方式更改提交历史记录.

When you do a git pull origin master,
git pull performs a merge, which often creates a merge commit. Therefore, by default, pulling from the remote is NOT a harmless operation: it can create a new commit sha that didn’t exist before. This behavior can confuse a user, because what feels like it should be a harmless download operation actually changes the commit history in unpredictable ways.

要避免这种情况,您需要

To avoid this, you need

git pull --ff-only

(还是不?继续阅读,看看哪一个适合您的需求)

(or not? read on to see which one fits your needs)

使用 git pull --ff-only ,Git仅在可以快速转发"而不创建新提交的情况下才会更新您的分支.如果无法做到这一点, git pull --ff-only 只会中止并显示一条错误消息.

With git pull --ff-only, Git will update your branch only if it can be "fast-forwarded" without creating new commits. If this can’t be done, git pull --ff-only simply aborts with an error message.

您可以将Git客户端配置为默认情况下始终使用-ff-only ,因此即使您忘记了命令行标志,也可以得到此行为:

You can configure your Git client to always use --ff-only by default, so you get this behavior even if you forget the command-line flag:

git config --global pull.ff only

注意:-global 标志将更改应用于计算机上的所有存储库.如果只希望您所在的存储库具有此行为,请省略该标志.

Note: The --global flag applies the change for all repositories on your machine. If you want this behaviour only for the repository you're in, omit the flag.

来自此处

乔(Joe)在回答中指出,此警告已添加到Git 2.27中.

This warning was added in Git 2.27, as pointed out by Joe in his answer.

这是完整的警告内容:

在不指定如何协调分歧分支的情况下进行拉动是灰心.您可以通过运行以下命令之一来抑制此消息下一次拉动之前的某个时间执行命令:

git config pull.rebase false#merge(默认策略)
git config pull.rebase true#rebase
仅限git config pull.ff仅限#快速转发

您可以将"git config"替换为使用"git config --global"设置默认值对所有存储库的偏好.您还可以传递--rebase,--no-rebase,或--ff-only在命令行上以覆盖每个配置的默认值调用.

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.

该警告显示三个命令作为选项,所有这些命令都会禁止显示该警告.但是它们有不同的用途:

The warning presents three commands as options, all of these will suppress the warning. But they serve different purposes:

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

这将保留默认行为并禁止显示警告.

This keeps the default behaviour and suppresses the warning.

git config pull.rebase true      # rebase

这实际上是在远程分支的顶部提交的,在本地和远程维护一个分支(不同于默认行为,其中涉及两个不同的分支-一个在本地,另一个在远程),并且要结合使用这两个分支,合并).

This actually commits on top of the remote branch, maintaining a single branch both locally and remotely (unlike the default behaviour where two different branches are involved - one on local and the other on remote - and, to combine the two, a merge is performed).

git config pull.ff only          # fast-forward only

仅当可以快速转发本地分支时,才执行拉取.如果没有,它将简单地中止并显示一条错误消息(并且不会创建任何提交).

This only performs the pull if the local branch can be fast-forwarded. If not, it simply aborts with an error message (and does not create any commits).

更新:

如果您具有 Git 2.29 或更高版本,则可以将 pull.ff 设置为 false true only 摆脱警告.

If you have Git 2.29 or above, you can now set pull.ff to false, true or only to get rid of the warning.

git config pull.ff true

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

true - This is the default behaviour. Pull is fast-forwarded if possible, otherwise it's merged.

git config pull.ff false

false -永远不会快速拉入,并且始终会创建合并.

false - Pull is never fast-forwarded, and a merge is always created.

git config pull.ff only

-如果可能的话,pull快速转发,否则操作将中止并显示错误消息.

only - Pull is fast-forwarded if possible, otherwise operation is aborted with an error message.

这篇关于如何处理这个git警告?“不建议在不指定如何协调分歧分支的情况下进行拉动".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆