gitdiffgithooksgit-diffbeyondcompare

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.

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.


Solution

    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