Using git hooks to create a diff report for every file that has changed for the current commit

I’m trying to create a git hook to create a diff report for every file that has changed between my code and the server’s code.

Most solutions I have seen say to use git’s diff command to create the report, but I need this done for every file that has changed AND I need it to be created in beyond compare specifically as a side by side HTML report.

  • Sourcetree does not launch Beyond compare external merge tool
  • How can I import a directory structure into SVN, keeping the file and folder modifed dates the same?
  • How to use svn with beyond compare 3
  • OSX Using Beyond Compare as git difftool
  • Beyond Compare 2 as Git Mergetool
  • How to configure Beyond compare with Git command line
  • So, for every file that has changed, I would need to call beyond compare to create some file.html detailing what has changed. If 63 files changed, I would want 63 html files showing a diff of the changes.

    I have a rough idea of how to automate beyond compare to create the diff, I just don’t know how I’d get the paths of the files that have changed along with the paths to the local cache of the remote files that have changed.

    Has anyone done anything like this?

    EDIT – I wanted to use githooks because I wanted to have the diff files generated automatically for every commit without anyone having to think about it. This is part of our check in process now (as dictated by management) and it’s tedious to do manually for every file that has changed.

  • Can “git fetch” be told not to use “git upload-pack” for local repositories?
  • How to make GIT ignore my changes
  • git clone give an empty repository but the repository isn't empty
  • Adding remote upstream to git repo on bit bucket
  • Synchronizing databases between testing and production environment with git
  • GitHub: how to add Subfolders to a GitHub-Repository
  • 2 Solutions collect form web for “Using git hooks to create a diff report for every file that has changed for the current commit”

    1. To list the changed files:

      git diff --name-only
    2. To print the content of a file at a specified revision:

      git show <revision>:<file>
    3. Beyond Compare seem to accept stdin as input by adding - to the command.

    Combining these, assuming you are on windows and assuming the server is on the origin/master branch, you could do something like this: (note that I did not test this)

    for f in $(git diff --name-only)
        git show origin/master:"$f" | BCompare.exe "$f" - # add correct option(s) before "$f" to generate html

    Beyond compare didn’t seem to like using the piped in text with an argument list, so I ended up going with something like this:

    for f in $(git diff --name-only --cached); do
        git show HEAD:"$f" > tempRemote.dat
        "C:\Program Files (x86)\Beyond Compare 3\BCompare.exe" "$f" tempRemote.dat "C:\output\output${COUNTER}.html" @"script.txt"
        rm tempRemote.dat
    Git Baby is a git and github fan, let's start git clone.