nerdess
nerdess

Reputation: 10920

How can I manually run the hook post-receive on git?

I've pushed a website to my remote server via Git but got the error

cannot run post-receive: No such file or directory

So the stuff is on the server, it has just not been deployed to my /public folder.

I do however have a post-receive file so I am not sure why it was not found. Now I thought all I need to do is manually run this post-receive hook to do the checkout though I don't know how...

Upvotes: 17

Views: 13271

Answers (1)

Barend
Barend

Reputation: 17444

A hook is an executable shell script. You can execute it from the command line if you need to run it by hand, although constructing the expected stdin inuput is somewhat tedious if your repo has more than one head (that is, you use branches). There should be a low-level command to do this for you, but I don't know this offhand.

Assuming a bash shell and a single branch in your git repo...

# Print the log with full hashes and commit subject, so that you can
# figure out which hashes to use for the FROM and TO range.
/path/to/repo$ git log --pretty=%H\ %s

# assuming the FROM commit identifies as 999988887777
# and te TO commit identifies as 000011112222
# (Note: use the full length hashes; I've shortened them for the example)
/path/to/repo$ .git/hooks/post-receive <<MARK
999988887777 000011112222 refs/heads/master
MARK

...the above should work just like the real thing.

Upvotes: 25

Related Questions