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?
有一个正在运行的服务器,服务器上有一个git实例。我希望每次用户向服务器推送git时都运行一个脚本。我希望我的脚本被执行,然后git继续推进。工作个队伍吗?
3 个解决方案
#1
3
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.
我不确定你是想让剪刀在推之前还是推之后运行。这是预推的答案。但如果你想要后推(i)。e后推)你必须相应地改变预推钩检查是否成功推,然后你可以做后推的事情。
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.
正如@Travis所建议的,您正在寻找的是git hook。因此,要执行脚本预推,必须在.git/hook中创建预推文件。因此,在本例中,将您的一堆代码放入到postpost脚本文件中。git/hook /pre-push并保存它。然后通过chmod +x .git/hooks/pre-push使其可执行。成功完成后,您将能够看到脚本在每次运行push命令时被执行。
PS: Please note that I haven't tested this whole but expected to work in this way.
PS:请注意,我还没有对整个系统进行测试,但是我希望它能这样工作。
In Short, assuming you(Linux user) are in the project directory
简而言之,假设您(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
#2
0
You should look into git hooks:
你应该看看git hook:
8.3 Customizing Git - Git Hooks
8.3自定义Git挂钩
and, another site regarding this technology:
另一个关于这项技术的网站:
githooks.com
#3
0
You've tagged this GitHub so I'm assuming that you are referring to public GitHub and not GitHub enterprise.
您已经标记了这个GitHub,所以我假设您指的是公共GitHub,而不是GitHub enterprise。
You cannot run a script "server-side" on GitHub's servers because that would obviously be a massive vulnerability but you can set up a web hook to trigger a script on another server.
您不能在GitHub的服务器上运行脚本“服务器端”,因为这显然是一个巨大的漏洞,但是您可以设置一个web hook来触发另一个服务器上的脚本。
Basically whenever someone does a push, a specific URL will be sent data about the push. You can then trigger a script from this. For more information on web hooks, see the GitHub API docs.
基本上,只要有人推,一个特定的URL就会被发送关于推的数据。然后您可以从中触发一个脚本。有关web挂钩的更多信息,请参见GitHub API文档。
#1
3
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.
我不确定你是想让剪刀在推之前还是推之后运行。这是预推的答案。但如果你想要后推(i)。e后推)你必须相应地改变预推钩检查是否成功推,然后你可以做后推的事情。
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.
正如@Travis所建议的,您正在寻找的是git hook。因此,要执行脚本预推,必须在.git/hook中创建预推文件。因此,在本例中,将您的一堆代码放入到postpost脚本文件中。git/hook /pre-push并保存它。然后通过chmod +x .git/hooks/pre-push使其可执行。成功完成后,您将能够看到脚本在每次运行push命令时被执行。
PS: Please note that I haven't tested this whole but expected to work in this way.
PS:请注意,我还没有对整个系统进行测试,但是我希望它能这样工作。
In Short, assuming you(Linux user) are in the project directory
简而言之,假设您(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
#2
0
You should look into git hooks:
你应该看看git hook:
8.3 Customizing Git - Git Hooks
8.3自定义Git挂钩
and, another site regarding this technology:
另一个关于这项技术的网站:
githooks.com
#3
0
You've tagged this GitHub so I'm assuming that you are referring to public GitHub and not GitHub enterprise.
您已经标记了这个GitHub,所以我假设您指的是公共GitHub,而不是GitHub enterprise。
You cannot run a script "server-side" on GitHub's servers because that would obviously be a massive vulnerability but you can set up a web hook to trigger a script on another server.
您不能在GitHub的服务器上运行脚本“服务器端”,因为这显然是一个巨大的漏洞,但是您可以设置一个web hook来触发另一个服务器上的脚本。
Basically whenever someone does a push, a specific URL will be sent data about the push. You can then trigger a script from this. For more information on web hooks, see the GitHub API docs.
基本上,只要有人推,一个特定的URL就会被发送关于推的数据。然后您可以从中触发一个脚本。有关web挂钩的更多信息,请参见GitHub API文档。