0

I have feature/bug-fix branch (say topic) with a bunch of commits and want to present them to my colleagues before merging them into master. I can manually find the common ancestor of my branch and the master branch and compare that to its tip:

$ git diff d0a2eaf..03a025f

Is there a more elegant way to do this?

Bengt
  • 14,011
  • 7
  • 48
  • 66
  • possible duplicate of [how to view changed files on git branch and difference](http://stackoverflow.com/questions/17493925/how-to-view-changed-files-on-git-branch-and-difference) – Bengt Sep 19 '13 at 19:05

2 Answers2

0

You can automate finding the common ancestor using git merge-base and that to the tip of your branch:

$ git diff `git merge-base master topic` topic

Or simply use git diff's dot-notation for "Comparing branches" to view changes that occurred on the topic branch since when it was started of the master branch:

$ git diff master...topic
Bengt
  • 14,011
  • 7
  • 48
  • 66
  • Note that `git diff` effectively special-cases the three-dot syntax, `master...my-branch`, to do just that. – torek Sep 19 '13 at 18:35
0

if you current branch is your feature branch, doing a git diff master will do a diff between your current HEAD and the named branch (which is essentially exactly what you're mentioning).

g19fanatic
  • 10,567
  • 6
  • 33
  • 63
  • This requires interactive context switching (`git checkout topic`), which may not be possible with an unclean working copy. It would be more elegant to get the diff without depending on the working copy. – Bengt Sep 20 '13 at 20:33