Git 提交后挂钩作为后台任务
我有一个脚本,我需要在提交到 git 修订控制下的项目后运行该脚本。因此,我在项目 .git 目录的 /hooks 子目录中创建了一个提交后挂钩,将其命名为“post-commit”并为其提供以下内容:
#!/bin/sh
# I am a post-commit hook
/usr/local/bin/my_script &
my_script 是可执行的,并且在 /bin/sh 中运行良好。事实上,它的运行时间为几秒钟,所以我希望它在后台运行并与当前 shell 分离。这就是为什么我在后面加上“&”到我的钩子上。
现在的问题是,“&”似乎被忽略了。当我在 OSX Lion 下使用 gitx 0.7.1 提交时,gitx 恰好在 my_script 需要运行的时间段内挂起。
我尝试了很多,但没有将进程本身置于后台。
这里有什么问题吗?
I have a script, that I need to run after committing to a project under git revision control. Therefore I created a post-commit hook in my projects .git directory in the subdirectory /hooks, named it 'post-commit' and gave it the following contents:
#!/bin/sh
# I am a post-commit hook
/usr/local/bin/my_script &
my_script is executable and runs fine in /bin/sh. In fact it has a runtime of several seconds, so I want it to be backgrounded and detached from the current shell. That's why I put the trailing '&' to my hook.
The problem now is, that the '&' seems to be ignored. When I commit using gitx 0.7.1 under OSX Lion, gitx hangs for exactly the period that my_script needs to run.
I tried a lot, but do not get the process itself into the background.
What is wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
它对我来说是这样的:
Here's how it works for me:
您还可以使用
at
命令。您可能必须先安装它或者:
请参阅 at(1) 手册页以获取有关 at (
man at
或 在线版本)You could also use the
at
command. You may have to install it firstOR:
See the at(1) manual page for more info about at (
man at
or the online version)尝试使用 nohup
Try to use nohup
如果将
#!/bin/sh
更改为#!/bin/bash
(假设您可以使用 bash),并使用nohup
,你的例子应该有效。If you change
#!/bin/sh
to#!/bin/bash
(assuming you're ok with using bash), and usenohup
, your example should work.