Alright! You want to get up to speed with a new git repository? You got it. Here are some quick reference notes and tools to use to see what’s been going on.
Caveat: I’m a little rushed writing this so it’s going to be more of a highlights post than a fully detailed tutorial. If I feel like there’s a lot of material that I’m having to skip I’ll make more detailed posts on specific points. Or maybe I’ll write up a PDF or epub for handy reference.
Gary Bernhardt is pretty much the guy here. If you want to really get to know git and learn some amazing tricks for working with a git repo as efficiently as you work with code then you should subscribe to Destroy All Software
To follow along you’ll need to head to Gary’s dotfiles repo and snag all his cool git scripts and aliases.
For the following examples we’ll be analyzing the twitter/bootstrap repository on github.
Let’s get to it!
git-churn is a script that shows the “churn” (modified files) sorted by increasing frequency.
1 2 3 4 5 6 7 8 9 10 11
Let’s check out our repo and see what the big files are.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
Cool, so we can see that they probably generate that zipfile automatically or at least rebuild it frequently.
Interestingly, the docs get some significant attention. It seems that the docs are not an afterthought in this repo!
Let’s see what fat has been up to.
1 2 3 4 5 6 7 8 9 10 11 12 13
Cool eh? This is really handy when you are joining a new team and want to see what your coworkers have had in the fire.
So now you’ve got a shortlist of Interesting Files from git churn, time to see what’s been going on with them.
You can pass specific files to
git log and get the history for just those files. Handy!
1 2 3 4 5
pretty git log
This is provided in Gary’s .githelpers, but if you want to get a glimpse without some of the niceities you can run this:
To get output like this:
Gorgeous isn’t it? The text in red after a commiter’s name is the branch. From this listing we can see that master is the most current version of the code and is a few commits ahead of v2.0.3. This is a really handy way to see the state of an entire repo, use it.
git-divergence is another script from Gary. This one shows the incoming/outgoing changes between two commits. Super useful for comparing, say, a feature branch against master (or develop, whatever it was branched from).
Let’s checkout those commits between master (which we’re currently on) and v2.0.3.
With this output we see the commit message and each of the files altered with line-count diffs.
From this quick snapshot we’re happy to see that the authors in this repo are making small commits with few changes. Be worried if you see lots of commits that have so many files they scroll off the view and huge line diffs.
The vim-fugitive plugin for vim is chock full of git goodness. Even if you aren’t a vim user you might find its blame view helpful.
In vim, with the plugin, in a file that you are interested in analyzing you just run
:Gblame to get a great view of who’s been working on what.
So we have Mark Otto to blame (credit?) for all the “le comments”. :-)
Sorry for the whirlwind pace here. I wrote this straight through in one lunch break. But hopefully you’ve gotten at least a couple tips or tricks, and I’ve narrowly achieved my deadline of a new post this week. Woot!
Keep an eye on: Metior
Metior is a tool that looks like it could be really interesting someday. Currently it’s just an API around the git log configured with some interesting, but basic, reports. The “Future plans” have some good bullet points so I’ll be keeping an eye on this project.