默认的 git 发散合并策略是什么?
我最近开始使用一台新机器,在我之前在 GitHub 上在线解决了一些问题并忘记拉取后,在尝试推送到分支时注意到了此错误提示。
所以我拉了,通常当我这样做时,我会得到一个已更改的文件列表,需要解决它们,添加它们,然后推送。
然而,今天遇到这种情况时,却发生了不同的情况。我收到这样的消息:
hint: You have divergent branches and need to specify how to reconcile them.
hint: You can do so by running one of the following commands sometime before
hint: your next pull:
hint:
hint: git config pull.rebase false # merge
hint: git config pull.rebase true # rebase
hint: git config pull.ff only # fast-forward only
hint:
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
fatal: Need to specify how to reconcile divergent branches.
每当设置新机器时,我以前从未见过这种情况。我在另外两台机器上使用相同的 .gitconfig
,但我没有看到此消息:
[user]
name = my name
email = my email
[format]
numbered = auto
[color]
branch = yes
diff = auto
pager = yes
status = auto
我已经这样做了很多次,但我突然失忆了。我不记得 Git 曾经有过这样的提示/错误(6 年了)。这是新的吗?也许我可以看看 Git 源代码的历史?如果不是,默认是什么?
I recently started using a new machine and noticed this error hint when attempting to push to a branch after I resolved something online earlier on GitHub and forgot to pull.
So I pulled, and usually when I do this, I would get a list of the files that had changes and need to resolve them, add them, and then push.
However something different happened today when encountering this. I got this message:
hint: You have divergent branches and need to specify how to reconcile them.
hint: You can do so by running one of the following commands sometime before
hint: your next pull:
hint:
hint: git config pull.rebase false # merge
hint: git config pull.rebase true # rebase
hint: git config pull.ff only # fast-forward only
hint:
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
fatal: Need to specify how to reconcile divergent branches.
Whenever setting up a new machine, I've never seen this before. I'm using the same .gitconfig
on two other machines where I haven't seen this message:
[user]
name = my name
email = my email
[format]
numbered = auto
[color]
branch = yes
diff = auto
pager = yes
status = auto
I've done this many times and I suddenly have amnesia. I do not recall this hint/error from Git ever (6 years). Is this new? Maybe I can look at history of Git's source? If not, what's the default?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它确实是新的(在 Git 2.27 中部分引入,并在 2.29 中修复):您现在可以并且应该将
pull.rebase
和pull.ff
配置为某些设置(s )。之前的default默认值相当于
pull.rebase false
和pull.ff true
。这使得 git pull 运行 git merge,如果可能的话进行快进非合并“假”合并,如果不可能则进行真正的合并。将
pull.ff
配置为only
使git pull
运行与git merge --ff-only
等效的内容第二个命令(前提是你没有变基)。这是我个人的一般偏好,但我并没有到处都有 Git 2.29 或更高版本,所以我仍然使用我自己的 rungit fetch
,然后四处看看,然后决定,也许使用我的 < code>git mff 别名来执行仅快进合并过程。It is indeed new (partly introduced in Git 2.27, with a fix in 2.29): you can and should now configure
pull.rebase
andpull.ff
to some setting(s).The previous default default was the equivalent of
pull.rebase false
andpull.ff true
. This makesgit pull
rungit merge
, doing a fast-forward non-merge "fake" merge if possible, or a real merge if not possible.Configuring
pull.ff
toonly
makesgit pull
run the equivalent ofgit merge --ff-only
as its second command (provided you're not rebasing). This is my general personal preference, but I don't have Git 2.29 or later everywhere, so I still use my own rungit fetch
, then poke around, then decide and maybe use mygit mff
alias to do a fast-forward-only merge process.对您的问题的简短说明:
Git 强制我们选择如何处理远程分支(例如 origin/develop)和本地分支(develop)之间的不同步,因此可以轻松修改行为并添加此消息来提醒您可能想要更改默认值。
要修复它,我们需要更改默认运行以下命令:
或将事件更好地作为全局默认值
Short explanation of your issue:
Git force us to choose how it should handle out of sync between our remote branch (e.g. origin/develop) and local branch (develop), so it made it easy to modify the behavior and added this message to remind you that you might want to change the default.
To fix it we need to change the default running the following:
or event better as a global default with
如果它有帮助,有人可以遵循这种替代方式
我不得不面对这个问题。但以下建议对我不起作用
最后我用另一种方式解决了这个问题。
步骤:
If it helps someone may follow this alternative way
I had to face on this issue. But below suggestion not worked for me
Finally I have solved this issue in another way.
steps :