有一个服务器正在运行并且上面有一个 git 实例。我希望每次用户执行 git push 到服务器时运行一个脚本。我希望我的脚本被执行,然后 git push 继续。任何解决方法?
我不确定您是否希望在推送之前或之后运行 scipt。这是我对预推的回答。但是如果你想要推送后(即推送后),你必须pre-push相应地改变钩子来检查推送是否成功,然后你就可以做推送后的事情。
正如@Travis 所建议的,git hooks这就是您正在寻找的那个。因此,要执行预推送脚本,您要做的就是pre-push在.git/hooks. 因此,在这种情况下,将一堆代码放入 pre-post 脚本文件中.git/hooks/pre-push并保存。然后使其可执行chmod +x .git/hooks/pre-push。成功完成此操作后,您将能够看到每次运行推送命令时都会执行脚本。
PS:请注意,我还没有测试过整个过程,但希望以这种方式工作。
简而言之,假设你(Linux 用户)位于项目目录中
vim .git/hooks/pre-push # then add your code and save the file
# Also put the shebang on top to identify the interpreter
chmod +x .git/hooks/pre-push # make it executable
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8228 次 |
| 最近记录: |