我在我的 ubuntu 服务器中设置了一个裸仓库。
在我将我的裸 git 仓库推送到服务器之后:
$ git push origin master
我希望使用最新推送更新我的非裸仓库的内容,如图所示,其中非裸仓库是我名为 workfiles 的实际工作目录。
$ cd /central/workfiles
$ git pull
$ exit
我听说过接收后 Hook ,但不知道如何设置。 我怎样才能达到同样的效果。
最佳答案
我更喜欢指定工作树和 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
作为commented below通过 ChrisV , 你也可以依赖 git checkout
而不是 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.
但这意味着 /central/workfiles
不是“非裸”git 存储库。它只是一个文件夹,您可以在其中检查裸仓库 /bare/repo.git
的内容。
参见 Brian Thomas的 answer有关该方法的示例。
这不符合 OP 规范。
关于git - 为裸 repo 设置接收后 Hook ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14453411/