git 如何解决 EGit Eclipse 插件中的“多个合并基础”错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12223439/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 07:27:15  来源:igfitidea点击:

How to work around "multiple merge bases" error in EGit Eclipse plugin?

giteclipse-pluginmergeegit

提问by robinst

Using eclipse egit plugin I've encountered "multiple merge bases" exception. Before I've managed to resolve the situation, but this time nothing helps. Even after creating additional commits and branches, cherry pick. Repository branches seems blocked to merge.

使用 eclipse egit 插件时,我遇到了“多个合并基础”异常。在我设法解决问题之前,但这一次没有任何帮助。即使在创建了额外的提交和分支之后,也可以挑选。存储库分支似乎无法合并。

This is the exception:

这是例外:

An internal error occurred during: "Merging with refs/remotes/origin/master".
Exception caught during execution of merge command. java.io.IOException: Multiple merge bases for:
 082a3a9846147a0e6df72d6cffa6d6e517275b7b
 4d6c573c52ebb0de091bd91dbcefcbcbd44e7534 found:
 c480f2b3683a5d0c5607984ea6393d61dfa9fba4
 9da20a3c6304059ed92296ef2decb6f04e7112df

回答by robinst

EGit

EGit

The recursive merge strategy needed for this is the default since EGit 3.0 (see bug 380314).

自 EGit 3.0 起,此所需的递归合并策略是默认设置(请参阅错误 380314)。

In case you are using an older version, see the download pagefor upgrading.

如果您使用的是旧版本,请参阅下载页面进行升级。

Workarounds

解决方法

Alternatively, try resetting to your last local commit before you made the last merge, and then merge with origin/master. Then if you made more changes on top of the original merge, cherry-pick these.

或者,尝试在进行最后一次合并之前重置为最后一次本地提交,然后与origin/master. 然后,如果您在原始合并之上进行了更多更改,请选择这些。

Another possibility would be to do the merge using C git (on the console), it can handle that situation.

另一种可能性是使用 C git(在控制台上)进行合并,它可以处理这种情况。

回答by Mark Booth

If you can't or don't want to update to the latest EGit, then the most reliable work around is (as robinst suggests) to recover from this state and then merge on the command line.

如果您不能或不想更新到最新的 EGit,那么最可靠的解决方法是(如robinst 建议的那样)从此状态恢复,然后在命令行上合并。

  • Note that it is important to recover from this properly, as a Multiple merge basesproblem leaves your repository in the middle of a merge state.
  • If you don't recover properly then the next commit you do will result in a merge commitwhich silently revertsall remote changes!
    • In other words, when you push, only your local changes will end up on the remote. All of the remote changes will look like they have been merged in, but will have been ignored, just like doing git merge -s oursbefore doing a push.
  • 请注意,正确地从中恢复很重要,因为Multiple merge bases问题会使您的存储库处于合并状态的中间。
  • 如果您没有正确恢复,那么您所做的下一次提交将导致合并提交,它会静默地恢复所有远程更改!
    • 换句话说,当您推送时,只有您本地的更改会在远程结束。所有远程更改看起来都已合并,但会被忽略,就像git merge -s ours在执行推送之前一样。

You can check to see if you are in a merge state by looking for MERGE_HEADand MERGE_MSGfiles in your .gitfolder. Just doing a git statustells you nothing to commit:

您可以通过查找文件夹中的MERGE_HEADMERGE_MSG文件来检查您是否处于合并状态.git。只是做一个git status告诉你nothing to commit

$ git status
# On branch master
# Your branch and 'origin/master' have diverged,
# and have 4 and 25 different commit(s) each, respectively.
#
nothing to commit (working directory clean)
$ cat .git/MERGE_HEAD 
1234567890abcdef1234567890abcdef12345678
$ cat .git/MERGE_MSG 
Merge remote branch 'origin/master'

You can then return to the state you were in before you attempted the merge from EGit.

然后,您可以返回到尝试从 EGit 合并之前所处的状态。

$ git reset --hard
HEAD is now at 0123456 Blah blah blah
$ cat .git/MERGE_HEAD .git/MERGE_MSG
cat: .git/MERGE_HEAD: No such file or directory
cat: .git/MERGE_MSG: No such file or directory

As always, this will lose any and all changes made since the last commit.

与往常一样,这将丢失自上次提交以来所做的所有更改。

  • Note: This is why it is a good idea to commit all changes before doing a pull or a merge.
    • If the pull or merge fails and your repository is left in an inconsistent state, you want to be able to reset back to a known good point before trying the pull/merge again.
  • As an alternative to committingbefore a pull/merge, you can also stashyour changes, perform the merge and then unstashthem. This is effectively like a mini rebaseof uncommitted changes on top of the merge, but with the safety net of a pre-merge commit.
  • 注意:这就是为什么在执行拉取或合并之前提交所有更改是个好主意的原因。
    • 如果拉取或合并失败并且您的存储库处于不一致状态,您希望能够在再次尝试拉取/合并之前重置回已知的好点。
  • 作为在拉取/合并之前提交的替代方法,您还可以存储更改,执行合并,然后取消存储它们。这实际上就像在合并之上的未提交更改的小型变基,但具有预合并提交的安全网。

Note that you could also do a git merge --abort, but on some versions of git, this recommends that you commit your changes, which you should not do if you want to avoid your remote changed being silently reverted (which you definitely don't want).

请注意,您也可以执行 a git merge --abort,但在某些版本的 git 上,这建议您提交更改,如果您想避免远程更改被静默还原(您绝对不想要),则不应该这样做。

You can now re-run the merge you originally wanted using the git command line, which will use the recursive resolve strategy and should thus work properly:

您现在可以使用 git 命令行重新运行您最初想要的合并,它将使用递归解析策略,因此应该可以正常工作:

$ git merge origin/master
Auto-merging ...
...
Merge made by recursive.
...
$ git --no-pager log -1 --oneline
2345678 Merge remote branch 'origin/master'