默认的 git 发散合并策略是什么?

发布于 2025-01-10 17:45:48 字数 1259 浏览 0 评论 0原文

我最近开始使用一台新机器,在我之前在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我要还你自由 2025-01-17 17:45:48

它确实是新的(在 Git 2.27 中部分引入,并在 2.29 中修复):您现在可以并且应该将 pull.rebasepull.ff 配置为某些设置(s )。

之前的default默认值相当于pull.rebase falsepull.ff true。这使得 git pull 运行 git merge,如果可能的话进行快进非合并“假”合并,如果不可能则进行真正的合并。

pull.ff 配置为 only 使 git pull 运行与 git merge --ff-only 等效的内容第二个命令(前提是你没有变基)。这是我个人的一般偏好,但我并没有到处都有 Git 2.29 或更高版本,所以我仍然使用我自己的 run git 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 and pull.ff to some setting(s).

The previous default default was the equivalent of pull.rebase false and pull.ff true. This makes git pull run git merge, doing a fast-forward non-merge "fake" merge if possible, or a real merge if not possible.

Configuring pull.ff to only makes git pull run the equivalent of git 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 run git fetch, then poke around, then decide and maybe use my git mff alias to do a fast-forward-only merge process.

明月夜 2025-01-17 17:45:48

对您的问题的简短说明:

Git 强制我们选择如何处理远程分支(例如 origin/develop)和本地分支(develop)之间的不同步,因此可以轻松修改行为并添加此消息来提醒您可能想要更改默认值。

要修复它,我们需要更改默认运行以下命令:

git pull --ff-only

或将事件更好地作为全局默认值

git config --global pull.ff only

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:

git pull --ff-only

or event better as a global default with

git config --global pull.ff only
三生殊途 2025-01-17 17:45:48

如果它有帮助,有人可以遵循这种替代方式

我不得不面对这个问题。但以下建议对我不起作用

- git config pull.rebase false  
- git config pull.rebase true   
- git config pull.ff only 

OR even adding 'git config --global pull.ff only' not worked

最后我用另一种方式解决了这个问题。

步骤:

- Create a new branch   // git create branch new_branch
- switch to new branch      // git checkout new_branch
- merge prev_branch to new_branch   // git merge origin prev_branch

If it helps someone may follow this alternative way

I had to face on this issue. But below suggestion not worked for me

- git config pull.rebase false  
- git config pull.rebase true   
- git config pull.ff only 

OR even adding 'git config --global pull.ff only' not worked

Finally I have solved this issue in another way.

steps :

- Create a new branch   // git create branch new_branch
- switch to new branch      // git checkout new_branch
- merge prev_branch to new_branch   // git merge origin prev_branch
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文