如何解决git的“不是我们可以合并的东西”错误 [英] How to resolve git's "not something we can merge" error

查看:2615
本文介绍了如何解决git的“不是我们可以合并的东西”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在git中将分支合并到master时遇到了一个问题。首先,我通过运行 git ls-remote 来获得分支名称。我们称该分支为分支名称。然后我运行了 git merge branch-name 命令并得到了以下结果:

I just encountered a problem when merging a branch into master in git. First, I got the branch name by running git ls-remote. Let's call that branch "branch-name". I then ran git merge branch-name command and got the following result:

fatal: branch-name - not something we can merge

如何解决这个错误?

推荐答案

我们不能合并的东西出现?,这个错误可能是由于分支名称中的拼写错误导致的,因为您试图拉取一个不存在的分支。

As shown in How does "not something we can merge" arise?, this error can arise from a typo in the branch name because you are trying to pull a branch that doesn't exist.

如果是不是问题(就像我的情况一样),很可能您没有要合并的分支的本地副本。 Git需要两个分支的本地知识才能合并这些分支。您可以通过检出要合并的分支并返回到要合并的分支来解决此问题。

If that is not the problem (as in my case), it is likely that you don't have a local copy of the branch that you want to merge. Git requires local knowledge of both branches in order to merge those branches. You can resolve this by checking out the branch to merge and then going back to the branch you want to merge into.

git checkout branch-name
git checkout master
git merge branch-name

这应该工作,但如果您收到一个错误,说:

This should work, but if you receive an error saying

error: pathspec 'remote-name/branch-name' did not match any file(s) known to git.

您需要先取出远程(可能但不一定是原点),然后再检出分行:

you need to fetch the remote (probably, but not necessarily, "origin") before checking out the branch:

git fetch remote-name

这篇关于如何解决git的“不是我们可以合并的东西”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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