我刚刚遇到了一个问题,合并一个分支到主git。首先,我通过运行git ls-remote来获得分支名称。我们称这个分支为“branch-name”。然后我运行git merge branch-name命令,得到如下结果:

fatal: branch-name - not something we can merge

如何解决此错误?


当前回答

在我的例子中,我试图从git存储库的子目录执行git命令。 请确保它是你用git初始化的目录,而不是它的子目录。

其他回答

当我做一个git合并BRANCH_NAME“some commit message”时,我得到了这个错误-我忘记为提交消息添加-m标志,所以它认为分支名称包括注释。

这可能是因为该分支不在您的本地。合并使用前

git fetch origin

我今天有这个问题,当我将另一个分支合并到我的直接从主后,我必须先签出并拉出我合并的分支,然后我才能成功地将这个分支合并到我的分支中。

git checkout branch-to-merge
git pull
git checkout my-branch-name
git merge branch-to-merge

如果包含引用的字符串是由另一个Git命令(或任何其他shell命令)生成的,请确保它的末尾不包含返回回车。你必须在将字符串传递给“git merge”之前剥离它。

注意,当这种情况发生时,这是非常明显的,因为错误消息在2行中:

merge: 26d8e04b29925ea5b59cb50501ab5a14dd35f0f9
 - not something we can merge

我必须建议先检查所有的分支机构,或者你要找的分支机构是否可用

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。复制粘贴将删除打印错误。