When I first read about GIT back in 2005, I thought it was a JARC “just another revision control” system, and quickly forgot about the whole thing. I think I at some point tried it out, but didn’t really understand (or appreciate) the difference between GIT and SVN which was the revision system I used (and knew) back then.

But a few years later (then at Google) I got persuaded to start using GIT because I had a tendency to “pollute” my changes before completion, thus once in a while submitting buggy code. And the reason: Branching is expensive in most RCSs (revision control systems), but not in GIT. I tried it out, then started to get new habits. And lo and behold: I got hooked.

My project since then has changed at Google, but I still use GIT for a few but important reasons:

  • Git branching makes it easy to try out code without polluting other ongoing work, even in the same directory tree. Its simply done by:

    git checkout -b test-something-out
    #  ... hack away ...
    git commit -a
    git checkout old-branch

    And then I can continue my work untouched. And at the same time keep my test-branch in case I want to continue in that direction again. Or I could merge that back into old-branch if I wanted that.

  • I can keep an almost never-ending list of ongoing branches on the same code and swap between them as I see the need. Still only one directory tree.
  • Merging is easy!
  • I can work locally with GIT and use a secondary RCS as the main repository, whichever my employer seem to prefer.
  • It’s really, really fast, even with tens of thousand of files to look at.

Git also has some quirks, and lacks some features. I’m a vim fan, and usually want to see diffs using gvimdiff, which works best with complete files (instead of just the diff patches). But I can only directly access the files from the same branch as I’m in (and current files), where I’d like to not only get the diffs relative to files in other branches, but simply get the file content. I currently uses a script based on the commands:

git log -1 --branches branch-to-diff-against | grep ^commit | sed 's/.* //'
git cat-file -p revision:path/to/file & my-temp-file
gvimdiff my-temp-file path/to/file

The only problem: git log -1 --branches blah will find the latest revision from any branch with the regex prefix “blah”, so I’m not guaranteed to get the right revision number… I guess I’ll have to add that one day.

EDIT - 21.05.2012

On getting a branch’s current revision ID, actually: git branch -a -v --no-abbrev did the job just perfectly, even though the result cleanup looks a bit bad.