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.

  • How do I configure BeyondCompare to ignore SCM replaced text in comments?
  • How to use Beyond Compare 3 with Atom and difftool command?
  • How do I make Beyond Compare ignore certain differences while comparing versions of Delphi Form Files
  • Beyond Compare 2 as Git Mergetool
  • git difftool to give directory compare?
  • OSX Using Beyond Compare as git difftool
  • 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.

  • Fixing github rails deployment
  • which version control is best suited for me?
  • Git status showing weird untracked “path_of_file\r” files, how to remove by command line
  • How do I reduce the size of a bloated Git repo by non-interactively squashing all commits except for the most recent ones?
  • Prevent merge at git pull
  • Git error: could not commit config file
  • 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
    do
    

    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:

    COUNTER=0
    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
        ((COUNTER++))
    done
    
    Git Baby is a git and github fan, let's start git clone.