Search code examples
gitmergebranchgit-diff

Diff only local changes in a merged branch in Git


Using Git, I branched from "trunk" the branch "A", then committed several changes. Then, I merged from "trunk" because it was merged with branch "B" and I had to sync with those changes. Then I made additional changes on branch "A".

This is a diagram of the tree:

branch A:   T1--A1--A2--M--A3--*
           /           / 
   trunk: T1----------T2
           \         /
branch B:   T1--B1--B2

Now, I'd like to diff only local differences in branch "A", but if I diff between the commit where I branched originally and the current working tree, I also see the changes merged from branch "B".

So, in a merged branch how can I see only the changes made in that branch excluding the merges?


Solution

  • The solution is actually simple: just git diff working tree against the commit from which the branch has been merged. In my example this means git diff T2.