I came across a RailsConf talk given by Scott Chacon last month. As previously, his git work is really good. His presentation style has also guided my Git the basics talk which I gave about a year ago.

Anyway, I want to summarize what I learned from Scott’s presentation…

  • If you want to read along, grab the PDF slides.

  • Scott likes (to smack around his) git; here is a quote:

    Scott Chacon has an understandable but borderline unhealthy obsession with GitIlya Grigorik

  • Scott wrote a second book about Git titled Pro Git. This will probably make it to my bookshelf if for no other reason then to support Scott’s work.

    Slightly related, I’ve also learned that there is an O’Reilly book titled Version Control with Git. I’ll have to have a look some day.

  • git diff HEAD...topic-branch

    While I often use the ... form with git log I have never used it to diff.

    Unlike git diff HEAD topic-branch which shows the diffs between current commit and the other branch, this form will show the changes since the common ancestor and HEAD. It’s essentially the same as saying:

     git diff $(git merge-base HEAD topic-branch) topic-branch
    
  • With some discipline one can use unrelated branches and subtree merge strategy as an alternative to submodules.

    It’s centrally interesting, but relies on several non-trivial steps to move changes from the integration branch to the submodule.

    This trick comes from Tim Dysinger’s article on Replacing Braid or Piston (for Git) with 40 lines of Rake. And I can see how it could be used as part of a larger infrastructure to do cool things.

  • Recnet versions of git started telling me when I did a typo on the git command. It usually suggests an alternative. Well with…

     git config --global help.autocorrect 1
    

    … you can make git actually execute the correction.

  • You can use git attributes to show niceer diffs for non-text files. For example…

     echo '*.png diff=exif' >> .gitattributes
     git config diff.exif.textconv exiftool
    

    … will tell git to use exiftool to convert a *.png to text so it can show you a git diff. Displaying this does not show you what changed in the image, but it’s better then just being told that the binary filed changed.

    One cool use of this could be to use antiword to convert the *.doc file to text so git can show a nice diff for MS Word files. Something like this is proposed for *.odf files here.

  • Scott also shows how you could use git filters to expand things like $Date:$ to show the last modified date of a file.

     cat >expand_date <<<END
     #!/bin/sh
     date=$(git log --pretty=format:"%ad" -1)
     sed -e "s,\\\$Date:[^$]*\\\$,\\\$Date: $date\\\$,g"
     END
    
     cat >clean_date <<<END
     #!/bin/sh
     sed -e "s,\\\$Date:[^\\\$]*\\\$,\\\$Date: \\\$,g"
     END
    
     git config filter.dater.smudge ./expand_date
     git config filter.dater.clean  ./clean_date
     echo '* filter=dater' >> .gitattributes
    
     echo '# $Date:$' > file
    

    And on next checkout that file will be smudged.

Naturally there may be other things in the slides that you may find interesting also… so go check it out.