有一台服务器在运行并且有一个git实例.我希望每次用户执行git push到服务器时都运行一个脚本.我希望我的脚本被执行然后git push继续.
有什么工作吗?
解决方法:
我不确定你是否想在推或之前运行一个scipt.所以这是我对推前的回答.但是如果你想推后推(即推后)你必须相应地改变推前挂钩以检查推是否成功,然后你可以做推后推送的东西.
正如@Travis所建议的那样,你正在寻找git hooks.因此,要执行预推脚本,您必须在.git / hooks中创建预推文件.所以在这种情况下,将你的一堆代码放在帖子前脚本文件.git / hooks / pre-push中并保存.然后通过chmod x .git / hooks / pre-push使其可执行.成功完成此操作后,您将能够在每次运行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
标签:git,bash,linux
来源: https://codeday.me/bug/20190611/1219062.html