linux - git post-receive checkout 到远程机器?

标签 linux git bash rsync

如果将以下脚本作为 hooks/post-receive Hook 添加到裸 git 存储库 foo.git:

#!/bin/sh
GIT_WORK_TREE=/bar git checkout -f

然后每当有人推送到存储库时,当前状态将在目录 bar 中更新。

这需要 barfoo.git 在同一台机器上。

修改它以便在远程机器上进行 checkout 的最简单方法是什么(比如 baz:/bar)?

一种方法是:

#!/bin/sh
GIT_WORK_TREE=/tmp/bar git checkout -f
rsync ... /tmp/bar baz:/bar

有没有更好的方法?也许不需要中间临时目录? (如果不是,传递给 rsync 的正确选项是什么,以便生成的目录与直接 checkout 的目录相同?)

最佳答案

GIT_WORK_TREE=/bar 表示 bar 是一个 git 仓库。

如果 bar 是远程端的一个 git 仓库,那么它可以从一个裸仓库 bare_bar.git (也在远程端) pull ,你可以推送到。

换句话说,您的 post-receive Hook 将通过 ssh 推送到 bare_bar 仓库,而那个裸仓库上的 post-receive 钩子(Hook)将触发从实际 repo bar:请参阅“Creating a git repository from a production folder”。


I'd prefer a solution that keeps the remote server free of any .git dirs (and even the git package itself ideally)

在那种情况下,您当前的接收后 Hook 及其 rsync 命令似乎是增量将新数据复制到远程工作树的唯一方法。

关于linux - git post-receive checkout 到远程机器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14469255/

相关文章:

php - 将 php 脚本作为守护进程运行

c# - 在linux上用c代码调用c#代码的最佳方法是什么

c++ - 提高那段代码的执行速度

git - 为什么git帮助在每个命令名称前添加 "git-"?

linux - 去路径然后 tar ?

linux - 打印包含命令的变量

linux - 直线代码指令导致的开销差异很大

Git merge 错误

linux - 将 git repo 移动到另一台服务器

perl - 每三次出现的字符串加倍