gitbeyondcomparebeyondcompare3

Directory comparison of Git branches


One of my favorite workflows with svn is to use Beyond Compare's folder comparison feature to see the net differences between two branches, or a branch and the trunk. Is there a way to do this in git without having to manually create multiple clones of the same repository?

As I ask this question, it occurs to me that I could write a script that would clone the current repo to a temporary directory, checkout the desired branch, and then call BCompare.exe with the two directories as arguments. The folder comparison view is invoked with

BCompare.exe path/to/folder1 path/to/folder2

Does this sound reasonable? Would I be able to delete the extra clone after I'm done with Beyond Compare?


Solution

  • It sounds like you've already figured out the right answer -- use git clone and git checkout to set up a directory to compare to, then run BCompare.exe. The below script might be a good starting point.

    #!/bin/sh
    (                              # execute in a subshell so you can continue
                                   #   working in the current shell
        set -o xtrace              # bash setting that echos each command before it's executed
        > /tmp/auto_bcompare_log   # truncate existing log file
        BRANCH="$1"                # get branch argument from command line
        TEMPDIR=`mktemp -d`        # get a temp directory
        CWD=`pwd`                  # remember the current directory
        git clone $CWD $TEMPDIR
        cd $TEMPDIR
        git checkout $BRANCH
        cd $CWD
        BCompare.exe $CWD $TEMPDIR
        rm -rf $TEMPDIR
    ) >> /tmp/auto_bcompare_log 2>&1 < /dev/null & # background and redirect
                                                   # stdout/stderr/stdin