Git“错误:分支'x'未完全合并". [英] Git "error: The branch 'x' is not fully merged"

查看:250
本文介绍了Git“错误:分支'x'未完全合并".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在master分支中使用的命令

git branch experiment
git checkout experiment

然后,我对文件进行了一些更改,提交了更改,并将新分支推送到GitHub.

git commit . -m 'changed files'
git push -u origin experiment

后来我决定将自己的实验分支合并到主分支中.

git checkout master
git merge experiment

最后,我将更改推送到GitHub.

git push -u origin master

一切顺利,直到我尝试使用删除实验分支

git branch -d experiment

我收到错误消息:

错误:分支实验"未完全合并.
如果确定要删除它,请运行"git branch -D实验".

我对git有点陌生,我不知道我可以合并两个分支还有多少.我在这里想念什么?

解决方案

注意.谢谢@slekse
那不是错误,而是警告.这意味着您将要删除的分支包含无法从其上游分支或HEAD(当前签出的修订版)中的任何一个进行的提交. 换句话说,当您可能丢失提交时¹.

在实践中,这意味着您可能会修改,重新设置基础或过滤提交,并且它们看起来不相同.

因此,您可以通过删除另一个分支来检出确实包含有关未引用的提交的分支,从而避免警告

您将要验证您实际上没有丢失任何重要的提交:

git log --graph --left-right --cherry-pick --oneline master...experiment

这将为您提供分支之间所有未共享的列表.如果您感到好奇,可能会在没有--cherry-pick的情况下有所不同,而这种不同很可能是您收到警告的原因:

--cherry-pick

省略任何引入与另一端"上的另一次提交相同的更改的提交.当提交集受到对称差异限制时.例如,如果您有两个分支,A和B,则通常只使用--left-right列出所有提交的一侧,就像上面该选项说明中的示例一样.但是,它显示了从另一个分支中精心挑选的提交(例如,"b上的3rd"可能是从分支A中精心挑选的).使用此选项时,这样的提交对将从输出中排除.


¹默认情况下,它们实际上只是一段时间后收集的垃圾.另外,git-branch命令不会检查所有分支的修订树.警告是为了避免出现明显的错误.

²(我的偏好是强制删除,但您可能需要更多的保证).

Here are the commands I used from the master branch

git branch experiment
git checkout experiment

Then I made some changes to my files, committed the changes, and pushed the new branch to GitHub.

git commit . -m 'changed files'
git push -u origin experiment

Later on I decided to merge my experiment branch into the master branch.

git checkout master
git merge experiment

Finally I pushed the changes to GitHub.

git push -u origin master

All went well until I tried deleting my experiment branch using

git branch -d experiment

I got the error message:

error: The branch 'experiment' is not fully merged.
If you are sure you want to delete it, run 'git branch -D experiment'.

I'm a bit new to git, and I don't know how much more I could possibly merge the two branches. What am I missing here?

解决方案

Note Wording changed in response to the commments. Thanks @slekse
That is not an error, it is a warning. It means the branch you are about to delete contains commits that are not reachable from any of: its upstream branch, or HEAD (currently checked out revision). In other words, when you might lose commits¹.

In practice it means that you probably amended, rebased or filtered commits and they don't seem identical.

Therefore you could avoid the warning by checking out a branch that does contain the commits that you're about un-reference by deleting that other branch.²

You will want to verify that you in fact aren't missing any vital commits:

git log --graph --left-right --cherry-pick --oneline master...experiment

This will give you a list of any nonshared between the branches. In case you are curious, there might be a difference without --cherry-pick and this difference could well be the reason for the warning you get:

--cherry-pick

Omit any commit that introduces the same change as another commit on the "other side" when the set of commits are limited with symmetric difference. For example, if you have two branches, A and B, a usual way to list all commits on only one side of them is with --left-right, like the example above in the description of that option. It however shows the commits that were cherry-picked from the other branch (for example, "3rd on b" may be cherry-picked from branch A). With this option, such pairs of commits are excluded from the output.


¹ they're really only garbage collected after a while, by default. Also, the git-branch command does not check the revision tree of all branches. The warning is there to avoid obvious mistakes.

² (My preference here is to just force the deletion instead, but you might want to have the extra reassurance).

这篇关于Git“错误:分支'x'未完全合并".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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