即使我没有要提交的新提交,如何强制在服务器上git运行post-receive挂钩?
背景
我使用git自动将网站部署到服务器。我在服务器的受保护区域中有一个裸仓库,还有一个post-receive钩子,用于检出内容并将某些文件系统地复制到public_html文件夹中。(受本教程的启发)
我已经厌倦了post-receive在服务器上手动修改钩子,所以post-receive现在我的钩子实际上从仓库中复制了自己的新版本:
#!/bin/sh
rm -rf ~/../protected/*
GIT_WORK_TREE=~/../protected git checkout -f
# Rewrite over this file with any updates from the post-receive file
cp ~/../protected/post-receive hooks/post-receive
# Delete public_html
# Copy stuff public_html
当然,问题在于新的post-receive挂钩永远不会运行。一个看似简单的解决方案只是重新推动,但现在一切都已更新。这很烦人,因为每次更新post-receive钩子时都要求我伪造新的提交。有没有一种方法可以在post-receive不伪造提交或ssh输入的情况下调用该钩子?
我尝试了什么
git push
git push -f
checkout -f我使用rm -rf ~/repo.git/refs/heads/master。这将删除master分支,允许每次推送。