1

I am trying to find the diff between the current working tree and another branch (e.g. master) not including the merge commits.

. --a--> . --b--> . (master)
 \       \
  c       \ (merge)
   \       \
    . ----- . --d--> . (current) --e--> (working tree)

Now, git diff master does show the working tree changes, however it also shows changes in master not in current (-b, c, d, e). I want to see these changes not in master, that is, I want to see c, d and e.

I've tried using the triple-dot notation or using git log, but these compare against the tip (last commit):

git diff master...
git diff master...current_branch

git log -p --no-merges current..master

returns c and d, i.e. they don't include e: the working tree.

How can I get this diff to include the working tree?

Community
  • 1
  • 1
Andy Hayden
  • 359,921
  • 101
  • 625
  • 535

1 Answers1

1

The key point to remember here is that if both branches share commit X then this adds nothing to the diff, that is, you don't see anything about commit X in the diff*.

Therefore you only need to diff against the branching point (which you can find with merge-base) and diff against that:

git diff $(git merge-base current master)

returns c, d and e.

This also works if the story is for those which are seemingly more complex (with several merges):

. --a--> . --b--> . --- . (master)
 \       \             /
  c       \ (merge)   / (merge)
   \       \         /
    . ----- . ----- . --d--> . (current) --e--> (working tree)

returns d and e.

* This explains why you don't see a in git diff master.

I bet you feel silly for asking now!

Community
  • 1
  • 1
Andy Hayden
  • 359,921
  • 101
  • 625
  • 535