为裸回购设置后接收挂钩 [英] Setting up post-receive hook for bare repo
问题描述
在将我的裸git仓库推送到服务器后:
$ git push origin master
我希望我的非裸副本的内容能够通过最新的push进行更新,如下所示,其中非裸副本是我实际的工作目录,名为workfiles。
$ cd / central / workfiles
$ git pull
$ exit
我听说过接收后的挂钩,但不知道如何设置。
我该如何实现。
我更喜欢指定工作树和git目录,而不是依赖于cd:
/bare/repo.git/hooks/post-receive
#!/ bin / sh
GIT_WORK_TREE = / central / workfiles GIT_DIR = / central / workfiles / .git git pull origin master
exit
由于通过 ChrisV 评论,你也可以依靠 git checkout
代替 git pull
我相信
git checkout -f
比git pull
安全,因为合并是拉的一部分,可能会让事情变得凌乱如果需要手动修正。
但这意味着 / cen tral / workfiles
不是非裸的git回购。它只是一个文件夹,您可以在此检出裸回购的内容 /bare/repo.git
。
请参阅布赖恩托马斯的答案为例这种方法。
这不符合OP规范。
I have a bare repo set up in my ubuntu server.
After I push to my bare git repo to the server:
$ git push origin master
I want the contents of my non bare repo to be updated with the latest push as shown where the non bare repo is my actual work directory named workfiles.
$ cd /central/workfiles
$ git pull
$ exit
I have heard about the post-receive hook but do not know how to set up the same. How can i achieve the same.
I prefer specifying the working tree and git directory instead of relying on a cd:
/bare/repo.git/hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=/central/workfiles GIT_DIR=/central/workfiles/.git git pull origin master
exit
As commented below by ChrisV, you can also rely one a git checkout
instead of a git pull
I believe
git checkout -f
is safer thangit pull
, as the merge which is part of the pull has the potential to make things messy if manual fixups should be needed.
But that means /central/workfiles
is not a "non-bare" git repo. It is just a folder where you checkout the content of the bare repo /bare/repo.git
.
See Brian Thomas's answer for an example of that approach.
That would not fit the OP specification.
这篇关于为裸回购设置后接收挂钩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!