之后,git pull 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 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
从这里取
更新:正如Joe在其回答中指出的那样,此警告已添加到Git 2.27中。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句