Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get the affected files of a commit with a git post-commit hook?

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?

like image 851
bergyman Avatar asked Jan 27 '10 17:01

bergyman


People also ask

What is post commit hook in git?

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.

How do you find a list of files that have changed in a particular commit?

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.


2 Answers

Get the affected paths (relative to $GIT_DIR) of the current branch's head with

git show --pretty=oneline --name-only HEAD | sed 1d
like image 160
Greg Bacon Avatar answered Oct 04 '22 21:10

Greg Bacon


To get the raw data:

git diff-tree HEAD

like image 21
Tobu Avatar answered Oct 04 '22 22:10

Tobu