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

fatal: branch-name - not something we can merge

如何解决此错误?


当前回答

我的目标是将Branch2代码合并到Branch1中。

我在合并时得到了下面的消息。

我的分支Branch1和Branch2。请在项目文件夹中使用这些分支。

最初我只有分支1与脉泽,在这种情况下,我得到了下面提到的消息。

现在我已经签入了Branch2。

现在Branch1, Brnach2和master都在我的项目文件夹中。

现在开始合并步骤:

这是什么 起来

最后我们合并了Brnach2和Branch1

其他回答

如果您没有使用origin关键字,并且分支不是您自己的分支,也可能遇到此错误。

git checkout <to-branch> 
git merge origin/<from-branch>

下面的方法每次都对我有效。

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

如果您正在使用旧的教程,请检查分支是否命名为main或类似的名称,而不是master。

这个错误告诉您branch-name必须是您的一个分支的名称。

我也有同样的问题。我用下面的命令修复了它:

git checkout main
git fetch
git checkout branch_name
git fetch
git checkout main
git fetch
git merge branch_name

原因有很多:

git merge dependabot/npm_and_yarn/storybook/addon-essentials-6.4.19
merge: dependabot/npm_and_yarn/storybook/addon-essentials-6.4.19 - not something we can merge

您有一个具有特殊字符的分支名称。(就像我的情况): 解决方案:从不能合并的分支签出一个具有简单名称的新分支。这可能会有所帮助。

git checkout -b feature-addon
git checkout dev
git merge feature-addon

此错误可能是由于分支名称中的拼写错误引起的,因为您正在尝试拉取一个不存在的分支。 非常愚蠢,但很可能你没有你想合并的分支的本地副本。尝试git fetch来获取它