Git post-commit hook作为后台任务 [英] Git post-commit hook as a background task

查看:167
本文介绍了Git post-commit hook作为后台任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本,我需要在git修订控制下提交项目后运行。因此,我在子目录/钩子的项目.git目录中创建了一个post-commit钩子,将其命名为post-commit,并为其提供以下内容:

<$ p $
/ usr / local / bin / my_script&

my_script是可执行文件,可以在/ bin / sh中正常运行。实际上它有几秒的运行时间,所以我希望它能够与当前shell分离。这就是为什么我把尾随的'&'放在我的钩子上。

现在的问题是,'&'似乎被忽略了。当我在OSX Lion下使用gitx 0.7.1时,gitx正好挂起了my_script需要运行的时间。



我尝试了很多,但没有得到进程本身进入后台。



这里有什么不对?

解决方案

以下是它的工作方式:

 #!/ bin / sh 
#我是一个post-commit hook
nohup / usr / local / bin / my_script&> / dev / null&


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?

解决方案

Here's how it works for me:

#!/bin/sh
# I am a post-commit hook
nohup /usr/local/bin/my_script &>/dev/null &

这篇关于Git post-commit hook作为后台任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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