我刚刚遇到了一个问题,合并一个分支到主git。首先,我通过运行git ls-remote来获得分支名称。我们称这个分支为“branch-name”。然后我运行git merge branch-name命令,得到如下结果:
fatal: branch-name - not something we can merge
如何解决此错误?
我刚刚遇到了一个问题,合并一个分支到主git。首先,我通过运行git ls-remote来获得分支名称。我们称这个分支为“branch-name”。然后我运行git merge branch-name命令,得到如下结果:
fatal: branch-name - not something we can merge
如何解决此错误?
当前回答
我也有这个问题。分支看起来像'username/master',这似乎让git感到困惑,因为它看起来像我定义的远程地址。我用这个
git merge origin/username/master
工作得非常好。
其他回答
这是一个愚蠢的建议,但请确保分支名称中没有拼写错误!
正如在“我们不能合并的东西”是如何产生的?,此错误可能由分支名称中的拼写错误引起,因为您正在尝试拉取一个不存在的分支。
如果这不是问题所在(就像我的情况一样),那么很可能您没有想要合并的分支的本地副本。Git需要两个分支的本地知识,以便合并这些分支。您可以通过签出要合并的分支,然后返回要合并的分支来解决这个问题。
git checkout branch-name
git checkout master
git merge branch-name
这应该可以工作,但是如果您收到一个错误说
error: pathspec 'remote-name/branch-name' did not match any file(s) known to git.
在签出分支之前,你需要获取远程(可能,但不一定是“origin”):
git fetch remote-name
对我来说,当我尝试这样做时,问题出现了:
git merge -s ours --no-commit --allow-unrelated-histories <remote name>/develop
所以实际上我应该写master而不是develop,因为master是Subtree的分支名,而不是我实际的分支名。
这可能是因为该分支不在您的本地。合并使用前
git fetch origin
我必须建议先检查所有的分支机构,或者你要找的分支机构是否可用
Git branch -r
从列表中检查
origin/HEAD -> origin/main
origin/feature/branch_1
origin/feature/branch_2
origin/feature/branch_3
origin/feature/branch_4
origin/feature/your branch
建议从origin本身复制清单,然后git合并origin/feature/branch_2。复制粘贴将删除打印错误。