gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 12:34:51 24 4
gpt4 key购买 nike

如果将以下脚本作为 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com