如何解决 git 的“不是我们可以合并的东西”错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16862933/
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
How to resolve git's "not something we can merge" error
提问by Brian
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:
我刚刚在git中将一个分支合并到master时遇到了一个问题。首先,我通过运行获得了分支名称git ls-remote
。让我们称该分支为“分支名称”。然后我运行git merge branch-name
命令并得到以下结果:
fatal: branch-name - not something we can merge
How do I resolve this error?
如何解决此错误?
回答by Brian
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.
如“我们无法合并的东西”如何出现?,此错误可能由分支名称中的拼写错误引起,因为您试图拉取不存在的分支。
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 需要两个分支的本地知识才能合并这些分支。您可以通过签出要合并的分支然后返回到要合并到的分支来解决此问题。
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
回答by endless
It's a silly suggestion, but make sure there is no typo in the branch name!
这是一个愚蠢的建议,但请确保分支名称中没有拼写错误!
回答by Eneko Alonso
When pulling from a remote upstream, git fetch --all
did the trick for me:
从远程上游拉动时,git fetch --all
对我有用:
git remote add upstream [url to the original repo]
git checkout [branch to be updated]
git fetch --all
git merge upstream/[branch to be updated]
In other cases, I found the "Not something we can merge" error will also happen if the remote (origin, upstream) branch does not exist. This might seem obvious, but you might find yourself doing git merge origin/develop
on a repo that only has master
.
在其他情况下,我发现如果远程(原点,上游)分支不存在,也会发生“不是我们可以合并的东西”错误。这可能看起来很明显,但您可能会发现自己git merge origin/develop
在一个只有master
.
回答by spekulatius
I had this issue as well. The branch looked like 'username/master' which seemed to confuse git as it looked like a remote address I defined. For me using this
我也有这个问题。分支看起来像“用户名/主”,这似乎混淆了 git,因为它看起来像我定义的远程地址。对我来说使用这个
git merge origin/username/master
worked perfectly fine.
工作得很好。
回答by R.N.V.
The below method works for me every time.
以下方法每次都对我有用。
git checkout master
git pull
git checkout branch-name-to-be-merged
git pull
git checkout branch-name
git pull
git merge branch-name-to-be-merged
回答by Alok Kamboj
It may happen because that branch is not on your local. before merging use
这可能是因为该分支不在您的本地。合并使用前
git fetch origin
回答by Amar Magar
This error suggest that the branch from where you want to merge changes (i.e. in you case branch-name) is not present in you local, so you should checkout the branch and fetch the local changes. Checkout to your master branch and fetch, then follow the below steps:
此错误表明您要合并更改的分支(即在您的情况下是分支名称)在您的本地不存在,因此您应该检出该分支并获取本地更改。结帐到您的主分支并获取,然后按照以下步骤操作:
git checkout branch-name
git pull
git checkout new-branch-name
git merge branch-name
回答by Bilal Ahmed Yaseen
You are getting this error because the branch you want to merge doesn't exist on your local repository.
您收到此错误是因为您要合并的分支在您的本地存储库中不存在。
So, first checkout the brach you want to merge into master branch by the following command:
因此,首先通过以下命令签出要合并到 master 分支的分支:
git checkout branch_name_to_merge
After this try to merge it with master branch by the following command:
在此之后,尝试通过以下命令将其与 master 分支合并:
git merge branch_name_to_merge
回答by yala ramesh
This answer is not related to the above question, but I faced a similar issue, and maybe this will be useful to someone. I merged my feature branch to master as below:
这个答案与上述问题无关,但我遇到了类似的问题,也许这对某人有用。我将我的功能分支合并到 master ,如下所示:
$ git merge fix-load
I got the following error message:
我收到以下错误消息:
merge: fix-load - not something we can merge
合并:修复加载 - 不是我们可以合并的东西
I looked into above all solutions, but not none worked.
我首先研究了所有解决方案,但并非没有解决方案。
I found the issue was a spelling mistake on my branch name (actually, the merge branch name is fix-loads
).
我发现问题是我的分支名称拼写错误(实际上,合并分支名称是fix-loads
)。
回答by Vinay Sharma
In my opinion i had missed to map my local branch with remote repo. i did below and it worked fine.
在我看来,我错过了用远程仓库映射我的本地分支。我在下面做了,效果很好。
git checkout master
git remote add origin https://github.com/yourrepo/project.git
git push -u origin master
git pull
git merge myBranch1FromMain