每次git push后执行脚本 [英] Execute a script after every git push

查看:195
本文介绍了每次git push后执行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一台正在运行的服务器,上面有一个git实例.我希望每次用户将git push推送到服务器时都运行脚本.我希望执行我的脚本,然后执行git push继续.有什么解决方法吗?

There is a server running and has a git instance on it. I want a script to run everytime a user does git push to the server. I want my script to be executed then git push to continue. Any work arounds?

推荐答案

我不确定是否要在推之前或之后运行scipt.所以这是我对预推的答案.但是,如果要后推(即在推后),则必须相应地更改 pre-push 挂钩,以检查是否成功推入,然后可以进行后推.

I am not sure If you want a scipt to run prior to push or after. So here is my answer for pre-push. But if you want post-push (i.e after push) you have to change the pre-push hooks accordingly to check if pushed successfully and then you can do post push thing.

正如@Travis所建议的那样, git hooks 是您所需要的.因此,要执行脚本的预推,您要做的就是在 .git/hooks 中创建一个 pre-push 文件.因此,在这种情况下,请将您的代码堆放在发布前脚本文件 .git/hooks/pre-push 中并保存.然后通过 chmod + x .git/hooks/pre-push 使其可执行.成功完成此操作后,每次运行push命令时,您都可以看到脚本已执行.

As suggested by @Travis, git hooks is the one that you are looking for. So to execute a script pre-push, you have to do is to create a pre-push file in the .git/hooks. So in this case put your bunch of code in the pre-post script file .git/hooks/pre-push and save it. Then make it executable by chmod +x .git/hooks/pre-push. After you done with this successfully you will be able to see the script gets executed each time you do run push command.

PS:请注意,我还没有对此进行全面测试,但是希望可以通过这种方式工作.

PS: Please note that I haven't tested this whole but expected to work in this way.

简而言之,假设您(Linux用户)位于项目目录中

In Short, assuming you(Linux user) are in the project directory

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 push后执行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆