List changed files in git post-merge hook
The right Git command to list the changed files is diff-tree
Also the ORIG_HEAD
and HEAD
shortcuts may be used:
git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD
(see also: List all the files for a commit in Git)
[upd]
Perhaps it is better to use HEAD@{1}
in place of ORIG_HEAD
. I.e.:
git diff-tree -r --name-only --no-commit-id HEAD@{1} HEAD
In case of git pull --ff-only
command, when many commits can be added, HEAD@{1}
(inside post-merge hook) gives the last commit before this command, while ORIG_HEAD
gives just HEAD^
commit (at least in Git 2.1.4).
I think your best bet at that point is going to be the reflogs. If you've just fast-forwarded, the first line of HEAD's reflog will look like this:
63e21fb HEAD@{0}: merge origin/master: Fast-forward
So you should be able to print just the first line (git reflog -n 1
), check if it matches merge .*: Fast-forward$
, and if so, do git diff HEAD@{1} HEAD
. (You do want to look at the reflogs to verify that there was a fast-forward merge, probably, unless you can be confident from your script that it's the only possibility now.)