git - 为裸 repo 设置接收后 Hook

标签 git github githooks

我在我的 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 than git 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 Thomasanswer有关该方法的示例。

这不符合 OP 规范。

关于git - 为裸 repo 设置接收后 Hook ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14453411/

相关文章:

git - 使用 git 从项目框架创建新项目

git - 如何将 git 远程分支引用带到本地

github - 什么是 github 中的构建和传递按钮?

github - 调用gitk后如何继续使用GitBash?

GitHub:是否可以在私有(private) Gist 上与某人合作?

git - 从另一个钩子(Hook)调用一个 git 钩子(Hook)

Git:如何在预提交 Hook 中重新暂存暂存文件

git 不会忽略一个文件

git - 使用 meld 查看分支的差异?

git - 如何全局禁用git hooks