22 May 2013 wainstead   » (Master)

git-sdiff

I've longed for an implementation of sdiff for Git, but in the meantime I have something that works great on OS X. It requires FileMerge, part of the developer tools from Apple. Hat tip to my friend Dale.

This works when:
  • You are in a branch,
  • the branch differs from master, and
  • the file you're interested in differs in your branch and master.

    The command is:
    git difftool -t opendiff $(git log --pretty=format:%H -1 master -- $1) $(git log --pretty=format:%H -1 HEAD -- $1) -- $1

    (I'm using subshell calls to get the SHAs of the file for the branch and master; a simplified look at the command is:
    git difftool -t opendiff SHA-master SHA-branch -- path/to/file.py).

    I put this in a shell script and call it with the relative path to the file. Git is picky about that relative path; it should be relative to the current directory your shell is in, and a directory that is in the repository.

    Assume you named the script my-sdiff. Example:
    my-sdiff relative/path/to/file.py

    You'll be prompted at the shell with something like:
    Viewing: 'relative/path/to/file.py'
    Launch 'opendiff' [Y/n]:

    Just hit RETURN and FileMerge should open, showing you a side-by-side comparison of the file.

    Vexingly, if you get the relative path wrong, nothing happens! If you don't get the Y/n prompt you probably have the relative path wrong.
  • Latest blog entries     Older blog entries

    New Advogato Features

    New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

    Keep up with the latest Advogato features by reading the Advogato status blog.

    If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!