I'm using git within a perforce repository. I want to be able to know exactly what files were affected by a git commit so I can turn around with a post-commit hook and open those files for edit in perforce, so the perforce server knows about the changes.
Is there a way I can get a list, within the post-commit hook, of exactly what files were affected by the commit?
The post-commit hook is called immediately after the commit-msg hook. It can't change the outcome of the git commit operation, so it's used primarily for notification purposes. The script takes no parameters and its exit status does not affect the commit in any way.
To find out which files changed in a given commit, use the git log --raw command. It's the fastest and simplest way to get insight into which files a commit affects.
Get the affected paths (relative to $GIT_DIR
) of the current branch's head with
git show --pretty=oneline --name-only HEAD | sed 1d
To get the raw data:
git diff-tree HEAD
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With