Skip to content

more fun with git branches

One thing you learn after using git for awhile is you get used to trying random things, and it will often just work.  For example, if I want to know the differences between Linus’s kernel tree, and the Wolfson dev branch for a particular directory:

cbrake@happy:/build/linux-2.6$ git diff --stat origin/master..wolfson/dev sound/soc/codecs
 sound/soc/codecs/Kconfig       |  125 +++
 sound/soc/codecs/Makefile      |   34 +
 sound/soc/codecs/ad1939.c      |  690 +++++++++++++++
 sound/soc/codecs/ad1939.h      |   70 ++
 sound/soc/codecs/ad1980.c      |  309 +++++++
 sound/soc/codecs/ad1980.h      |   23 +
 sound/soc/codecs/cs4251x.c     |  771 +++++++++++++++++

Another way to get similar information is:

git log origin/master..wolfson/dev sound/soc/codecs

If I’m working on a topic branch, and I want to see a summary of all the changes in my Topic branch:

git log --stat origin/master..origin/my_topic_branch > my_topic_branch_changelog.txt

One of the neat things about git branches is you don’t have to be on a branch to interact with it.  You can diff, log, and checkout from branches other than the one you are currently in, and it is all very fast.  For instance, if I want to grab the latest copy of a file in the Wolfson dev branch, I can do something like:

git log checkout wolfson/dev sound/soc/codecs/wm9713.c

Not that this is a very good idea, but just to illustrate a point.  Git branches are amazing and make development work so much less tedious.


Leave a Reply

Your email address will not be published. Required fields are marked *