Git: Compare two branches

2012-07-18

I don’t know if this is common knowledge, but with git it’s very easy (and handy) to see which commits are unmerged between two branches. Suppose you do work on the master branch, then merge that into staging and production before a new release. To see what is going to go into the next staging release, you just pass a range to git log like this:

git log staging..master

That will show you the changes in master that have not yet been merged into staging. In general, the pattern is git log <since>..<until>. My intuition says the order is backwards here, since you’re giving the destination branch first, but it makes sense if you think about it. The destination branch is on an earlier commit than the source branch, so it’s going to come first.

You can use the same approach to get a diff:

git diff staging..master

I think this is really handy when reviewing code before a merge!

blog comments powered by Disqus Prev: Fonts, Credibility, and "Statistically Significant" Next: Skipping rescue blocks in Ruby