在Git中,如何在接受提交后配置钩子来运行服务器端命令?

时间:2021-12-28 15:37:05

I'm trying to figure out my way with the Django localistion stuff and from what i've understood, the makemessages command needs to be run every time you change some strings in code. I was thinking of simplifying this process by using a server-side Git hook.

我试图用Django本地化的东西弄清楚我的方式,根据我的理解,每次你在代码中更改一些字符串时都需要运行makemessages命令。我想通过使用服务器端Git钩子来简化这个过程。

I have no knowledge about Git hooks and couldn't find any resources on the web that did something like this. Is there a reason why one shouldn't have a Git hook to do something like this? If not, could you explain on how I could get the makemessages command to be run every time someone commits code to the repository?

我不知道Git钩子,也无法在网上找到任何类似这样的资源。有没有理由为什么不应该有一个Git钩子来做这样的事情?如果没有,你能解释我每次有人将代码提交到存储库时如何运行makemessages命令吗?

Thanks

1 个解决方案

#1


10  

Sure thing!

Add a script called post-receive to the server side git repository in the .git/hooks/ directory.

将名为post-receive的脚本添加到.git / hooks /目录中的服务器端git存储库。

Make sure that the file is executable.

确保该文件是可执行的。

Call makemessages from the script.

从脚本中调用makemessages。

Done! (I think...)

完成! (我认为...)

You'll find some example scripts in the directory already, with most available hooks.

您将在目录中找到一些示例脚本,其中包含大多数可用的挂钩。

Have a look at the online Pro Git book if you need more information on Git hooks.

如果您需要有关Git钩子的更多信息,请查看在线Pro Git书籍。

#1


10  

Sure thing!

Add a script called post-receive to the server side git repository in the .git/hooks/ directory.

将名为post-receive的脚本添加到.git / hooks /目录中的服务器端git存储库。

Make sure that the file is executable.

确保该文件是可执行的。

Call makemessages from the script.

从脚本中调用makemessages。

Done! (I think...)

完成! (我认为...)

You'll find some example scripts in the directory already, with most available hooks.

您将在目录中找到一些示例脚本,其中包含大多数可用的挂钩。

Have a look at the online Pro Git book if you need more information on Git hooks.

如果您需要有关Git钩子的更多信息,请查看在线Pro Git书籍。