Force git to run post-receive hook, even if everything is “up-to-date”

后端 未结 9 1771
再見小時候
再見小時候 2020-11-30 19:27

How do I force git to run a post-receive hook on a server even if I don\'t have a new commit to push?

Background

I use git to aut

9条回答
  •  温柔的废话
    2020-11-30 19:45

    I'm afraid you have to ssh to the server and run the hook script manually. git push doesn't make the server run the pre-push, pre-receive and post-receive hooks if there was nothing added (i.e. when git prints Everything up-to-date).

    The rest of the answer is about version-tracking the post-receive hook, so you can modify it without sshing to the server.

    Add a shell script named do-post-receive to the local repository:

    $ ls -ld .git
    $ echo 'echo "Hello, World!"' >do-post-receive
    $ git add do-post-receive
    $ git commit do-post-receive -m 'added do-post-receive'
    

    Replace your hooks/post-receive hook on the server with:

    #! /bin/sh
    while read OLDID NEWID BRANCH; do
      test "$BRANCH" = refs/heads/master && eval "$(git show master:do-post-receive)"
    done
    

    (Make sure to chmod 755 hooks/post-receive on the server.)

    Push your changes from the local repository to the server, and watch your do-post-receive code run:

    $ git push origin master
    ...
    remote: Hello, World!
    ...
    

提交回复
热议问题