In a git post-commit hook how do I get a list of the files that were changed?

Trying to figure out how long time was spent in a commit in a Git post-commit hook.

I’ve got a post-commit git hook that submits information over an API about the commit. What I want to do is figure out how long time was spent on the commit. Roughly.

  • Securing a Git Repository
  • How to find the hash of branch in Git?
  • TortoiseGit - When does it ask for a username and password?
  • git clone : no address associated with name
  • Git workflow on Heroku
  • Using non-npm-package git submodules in npm packages
  • My assumption is that a rough value can be figured out by finding the minimum of all the creation-time and modification-time of the files involved and compare with the maximum creation- and modification-time.

    I can easily do this in a Python script. If someone tells me it was the files “foo.txt”, “bar.txt” and “path/bla.txt” I can quickly do some arithmetic in a script based on these files.

    So, In a git post-commit hook how do I get a list of the files that were changed?

  • Git repo branching mistake fix
  • Git Flag Syntax: why do some flags have -one dash and some have --two?
  • Does git run “fetch” automatically, or only when I tell it to?
  • migrate from CVS to GIT without losing history
  • Show the original branch for a commit
  • When I do “git push”, what do the statistics mean? (Total, delta, etc.)
  • 2 Solutions collect form web for “In a git post-commit hook how do I get a list of the files that were changed?”

    When writing scripts around git, you should try to stick to the plumbing commands — their format is less likely to change and easier to parse. Here is a command which outputs the names of the paths which changed in a commit:

    git diff-tree -r --name-only --no-commit-id <tree-ish>

    That aside, you may wish to examine the index, as it contains timestamps about when the files were staged, which might give you an extra edge; however, I don’t believe there is a way to access this information.

    Been doing some research and found that git log --name-only -n1 is the best approach. It’s not difficult to get the min. and max. timestamps out of the files by doing a bit of string matching and using the Python os.stat module.

    As a general solution it still isn’t great because the modification times on the files doesn’t really reflect the reality of the time spent actually.

    Git Baby is a git and github fan, let's start git clone.