Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List changed files in git post-merge hook

Tags:

git

githooks

Is there a way for a post-merge hook get a list of all the files that were changed by a merge, even if it was a fast-forward?

like image 221
mckeed Avatar asked Feb 02 '11 16:02

mckeed


1 Answers

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).

like image 163
ruvim Avatar answered Nov 15 '22 07:11

ruvim