Git diff between current branch and master but not including unmerged master commits

前端 未结 4 1894
长情又很酷
长情又很酷 2021-01-29 20:17

I want a diff of all changes in a branch that is not merged to master yet.

I tried:

git diff master
git diff branch..master
git diff branch...master
         


        
4条回答
  •  萌比男神i
    2021-01-29 21:01

    git diff `git merge-base master branch`..branch
    

    Merge base is the point where branch diverged from master.

    Git diff supports a special syntax for this:

    git diff master...branch
    

    You must not swap the sides because then you would get the other branch. You want to know what changed in branch since it diverged from master, not the other way round.

    Loosely related:

    • Finding a branch point with Git?
    • How can I see what branch another branch was forked from?

    Note that .. and ... syntax does not have the same semantics as in other Git tools. It differs from the meaning specified in man gitrevisions.

    Quoting man git-diff:

    • git diff [--options] [--] […]

      This is to view the changes between two arbitrary .

    • git diff [--options] .. [--] […]

      This is synonymous to the previous form. If on one side is omitted, it will have the same effect as using HEAD instead.

    • git diff [--options] ... [--] […]

      This form is to view the changes on the branch containing and up to the second , starting at a common ancestor of both . "git diff A...B" is equivalent to "git diff $(git-merge-base A B) B". You can omit any one of , which has the same effect as using HEAD instead.

    Just in case you are doing something exotic, it should be noted that all of the in the above description, except in the last two forms that use ".." notations, can be any .

    For a more complete list of ways to spell , see "SPECIFYING REVISIONS" section in gitrevisions[7]. However, "diff" is about comparing two endpoints, not ranges, and the range notations (".." and "...") do not mean a range as defined in the "SPECIFYING RANGES" section in gitrevisions[7].

提交回复
热议问题