git diff not working on a bare repo, post-receive hook

526 views Asked by At

I am working on a post-receive hook on a bare repo. I want to get the file names that are changed and pushed in this bare repo (only the latest one). To get it i am using this command.

git diff --name-only HEAD^

This gives me error when I push to bare repo.

remote: fatal: This operation must be run in a work tree

I got that there is no worktree in bare repo so this command fails but how to get this run?

1

There are 1 answers

7
David Deutsch On BEST ANSWER

I believe the command you are looking for is git diff --name-only HEAD^ HEAD. This will compare the "current" commit with the commit before it.