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

后端 未结 9 1780
再見小時候
再見小時候 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:44

    Use '--allow-empty'

    After the initial push replacing the script, you can do this :

    git commit --allow-empty -m 'push to execute post-receive'
    

    The --allow-empty flag overrides git's default behavior of preventing you from making a commit when there are no changes.

    Use an alias and make your life even easier

    Add the following to ~/.gitconfig

    [alias]
        pushpr = "!f() { git push origin master;git commit --allow-empty -m 'push to execute post-receive';git push origin master; }; f"
    

    Now Just do git pushpr

    git pushpr
    

    This will push any changes to master, which in your case will trigger your post receive replacement script, then it will push again (using the --allow-empty flag) which will then execute your updated post-receive script.

提交回复
热议问题