Search code examples
gitdiffgit-diffdifftool

Git diff tool on every commit?


I would like to run git difftool HEAD~3.. path/to/file and have git open the difftool for each of those three commits so that I can see a side-by-side view of each commit.

How would I go about getting git-difftool to do that?


Solution

  • This would accomplish what you describe:

    git difftool HEAD~3 HEAD~2 path/to/file
    git difftool HEAD~2 HEAD~1 path/to/file
    git difftool HEAD~1 HEAD path/to/file
    

    Want to automate this process? Is it always three commits? Do you want a three-way merge?

    Update:

    If the answers are yes-yes-no, the solution will be:

    for i in {3..1}; do
      git difftool HEAD~$i HEAD~$((i-1)) path/to/file
    done
    

    Update:

    If the answers are yes-no-yes, it is essentially what @ruffin asks here. See my answer there.