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

问题描述

以下是我从master分支使用的命令

  git branch experiment 
git checkout experiment

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

  git commit。 
git push -u origin实验

请注意,在 git commit 。我被提示提交一条提交消息,并且我给了它一个。后来,我决定将我的实验分支合并到master分支中。

  git checkout master 
git合并实验

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

  git push -u origin master 

使用

  git分支-d实验


我收到错误消息错误:分支'实验'未完全合并。我有点新git,而且我不知道我还可以将两个分支合并在一起。我在这里错过了什么?

解决方案


这不是一个错误,它是一个警告。这意味着您要删除的分支包含无法从其上游分支或HEAD(当前签出的修订版)到达的提交。

实际上,这意味着您可能已经修改,重新发布或过滤了提交,并且它们没有提交似乎完全相同。



因此,您可以通过签出一个包含您所提交的提交的分支来避免警告 un-reference 删除那个其他的分支。

你需要验证你确实没有错过任何重要的提交:

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

这会为您提供分支之间的任何非共享列表。如果你很好奇,没有 - cherry-pick 可能有区别,这种差异很可能是你得到警告的原因:






¹他们真的只有在一段时间后才会收集垃圾,默认情况下。另外, git-branch 命令不检查所有分支的版本树。警告是为了避免出现明显的错误。



²(我的偏好是强制删除,但您可能想要获得额外的保证) p>

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 .
git push -u origin experiment

Note that after git commit . I was prompted for a commit message, and I gave it one. 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. 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?

解决方案

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:


¹ 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'未完全合并”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 20:31