Git “error: The branch 'x' is not fully merged”

前端 未结 12 1989
忘了有多久
忘了有多久 2020-12-04 04:34

Here are the commands I used from the master branch

git branch experiment
git checkout experiment

Then I made some changes to my files, commi

相关标签:
12条回答
  • 2020-12-04 05:03

    to see changes that are not merged, I did this:

    git checkout experiment
    git merge --no-commit master
    
    git diff --cached
    

    Note: This shows changes in master that are not in experiment.

    Don't forget to:

    git merge --abort
    

    When you're done lookin.

    0 讨论(0)
  • 2020-12-04 05:04

    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).

    0 讨论(0)
  • 2020-12-04 05:05

    Git is warning that you might lose history by deleting this branch. Even though it would not actually delete any commits right away, some or all of the commits on the branch would become unreachable if they are not part of some other branch as well.

    For the branch experiment to be “fully merged” into another branch, its tip commit must be an ancestor of the other branch’s tip, making the commits in experiment a subset of the other branch. This makes it safe to delete experiment, since all its commits will remain part of the repository history via the other branch. It must be “fully” merged, because it may have been merged several times already, but now have commits added since the last merge that are not contained in the other branch.

    Git doesn’t check every other branch in the repository, though; just two:

    1. The current branch (HEAD)
    2. The upstream branch, if there is one

    The “upstream branch” for experiment, as in your case, is probably origin/experiment. If experiment is fully merged in the current branch, then Git deletes it with no complaint. If it is not, but it is fully merged in its upstream branch, then Git proceeds with a warning seeming like:

    warning: deleting branch 'experiment' that has been merged
    to 'refs/remotes/origin/experiment', but not yet merged to
    HEAD.
    Deleted branch experiment (was xxxxxxxx).
    

    Where xxxxxxxx indicates a commit id. Being fully merged in its upstream indicates that the commits in experiment have been pushed to the origin repository, so that even if you lose them here, they may at least be saved elsewhere.

    Since Git doesn’t check other branches, it may be safe to delete a branch because you know it is fully merged into another one; you can do this with the -D option as indicated, or switch to that branch first and let Git confirm the fully merged status for you.

    0 讨论(0)
  • 2020-12-04 05:09

    You can simply figure out :

    git log --cherry master...experimental

    --cherry option is a synonym for --right-only --cherry-mark --no-merges

    git-log man page said

    it's useful to limit the output to the commits on our side and mark those that have been applied to the other side of a forked history with git log --cherry upstream...mybranch, similar to git cherry upstream mybranch.

    FYI. --cherry-pick omits equivalent commits but --cherry-marks doesn't. It's useful to find rebase and force updated changes between upstream and co-working public branch

    0 讨论(0)
  • 2020-12-04 05:09

    If you made a merge on Github and are seeing the error below. You need to pull (fetch and commit) the changes from the remote server before it will recognize the merge on your local. After doing this, Git will allow you to delete the branch without giving you the error.

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

    0 讨论(0)
  • 2020-12-04 05:11
    C:\inetpub\wwwroot\ember-roomviewer>git branch -d guided-furniture
    warning: not deleting branch 'guided-furniture' that is not yet merged to
             'refs/remotes/origin/guided-furniture', even though it is merged to HEAD.
    error: The branch 'guided-furniture' is not fully merged.
    If you are sure you want to delete it, run 'git branch -D guided-furniture'.
    

    The solution for me was simply that the feature branch needed to be pushed up to the remote. Then when I ran:

    git push origin guided-furniture
    /* You might need to fetch here */
    git branch -d guided-furniture
    
    Deleted branch guided-furniture (was 1813496).
    
    0 讨论(0)
提交回复
热议问题