Show non-merge differences for two commits in git

后端 未结 4 1323
野性不改
野性不改 2020-12-31 06:52

I have two commits, once of which is the ancestor of another. (They happen to be the start and end points of a branch. I don\'t think that matters, but I\'ll include it if i

相关标签:
4条回答
  • 2020-12-31 07:17

    I didn't know the --no-merges -o options but here another solution (I suppose that merges have been done from master) :

    git checkout -b temp
    git rebase --onto master branch-start branch-end
    git diff master
    
    0 讨论(0)
  • 2020-12-31 07:30

    Here's how I compare my checked out branch to master, excluding changes made during merge commits. I prefer using Meld's directory mode.

    # if you've never setup Meld as your difftool
    sudo apt install meld
    git config --global diff.tool meld
    
    # the command to see the differences
    git difftool -d --no-merges master
    
    0 讨论(0)
  • 2020-12-31 07:41

    Your question is slightly ambiguous but I think you want this.

    git log --no-merges -p branch-start..branch-end
    
    0 讨论(0)
  • 2020-12-31 07:44

    If your merges all came from the same branch (say master) or are all contained in another branch, you can use the solution from this question.

    Assuming you have a tree like the following:

             x---y-+-z-+-branch
            /     /   /
    ---a---b---c-+-d-+-e---master
    

    and the two commits you would like to compare are b and branch. Then instead of comparing the two commits directly, running

    git diff master...branch
    

    will show all changes done on the branch (x,y,z) excluding everything that is also on master (c,d,e, the merges). Note that this also ignores any changes done on master that are not yet in the branch.

    From the docs:

    git diff [--options] commit...commit [--] […​]

    This form is to view the changes on the branch containing and up to the second commit, starting at a common ancestor of both commits. "git diff A...B" is equivalent to "git diff $(git-merge-base A B) B".

    0 讨论(0)
提交回复
热议问题