5

I know about git diff branch1 branch2. However, I would like to see changes introduced in one branch only. I can get this functionality with:

git checkout branch1
git merge branch2
git reset origin/branch1
git diff

Is there a shorter way to do this?

Vlad the Impala
  • 14,192
  • 14
  • 66
  • 116

2 Answers2

9

You can do:

git diff branch1...branch2

(note that there are three dots)

... which will show you all the changes introduced on branch2 since it diverged from branch1 (or, strictly speaking, since the merge-base). The different uses of .. and ... in git diff and git log, can be a bit confusing, so you might find the diagrams in this answer helpful.

Community
  • 1
  • 1
Mark Longair
  • 385,867
  • 66
  • 394
  • 320
  • Hello sir. Nice answer. I see from your track record that I'm playing with the big boys trying to compete on git answers... :-) – Alex Wilson Jun 22 '12 at 20:09
  • @Alex: Well met, sir! I hope you're well. As it happens I'm only occasionally checking the git tag at the moment, but it's certainly a good one to follow – Mark Longair Jun 22 '12 at 20:20
3

You need to find the hash of the most recent common root of the two branches, for which you use git merge-base:

git merge-base branch1 branch2

Then after than you can get a log of the changes from that common root to the branch head with git log:

git diff <common base hash>..branch2
Alex Wilson
  • 6,440
  • 22
  • 43