如何设置 Git 挂钩,以便在推送到 ssh://peter@foo.com/~/bar.com.git 后,它会转到 ~/bar.com 并执行 git pull?

发布于 2024-11-03 05:46:54 字数 1352 浏览 0 评论 0原文

有人建议我在远程服务器上进行设置,

foo.com/~/bar.com       # live webpage content
foo.com/~/bar.com.git   # a bare repo

这样,从我的本地计算机上,我可以执行 a 操作

git push

,它将推送到远程计算机上的 foo.com/~/bar.com.git (完整路径为 ssh://[电子邮件受保护]/~ /bar.com.git

如何添加一个hook,使得push之后,远程服务器会cd ~/bar.com并做一个git pull 以便更新所有内容(与本地计算机相同)?(不需要像 Mercurial 那样运行 git update?)

(这与 无法 git 克隆文件夹一个服务器,然后编辑并 git Push? 现在我可以 ssh 到 foo.comcd ~/bar.com 并在那里等待并执行 <每当从本地计算机进行 git push 后,就执行 code>git pull,但最好自动完成)

更新:请仅发布如果您知道具体细节以及如何操作,请回答。如果您在此处进行谷歌搜索并发布第一个或第二个谷歌结果,则不会有任何帮助。

更新 2:我转到 ~/bar.com.git/hooks 并添加一个新文件 post-receive

#!/bin/bash

cd ~/bar.com
git pull ../bar.com.git master

其 内容为: chmod 755 post-receive,如果我在本地计算机上编辑文件,然后 git com -m "ok"git Push ,它不会使更改进入远程计算机的文件夹 ~/bar.com

I was advised to set up on a remote server

foo.com/~/bar.com       # live webpage content
foo.com/~/bar.com.git   # a bare repo

so, from my local machine, I can do a

git push

and it will push to foo.com/~/bar.com.git on the remote machine (the full path is ssh://[email protected]/~/bar.com.git

How can a hook be added, so that after the push, the remote server will cd ~/bar.com and do a git pull so that all content is updated (the same as the local machine)? (no need to run git update like for Mercurial?)

(this is related to Cannot git clone a folder on a server and then edit and git push? right now I can ssh to foo.com and cd ~/bar.com and wait there and do a git pull whenever after a git push from the local machine, but it'd be nice to have it done automatically)

Update: please only post an answer if you know specific details and how to do it. If you google and post the first or second google result here, it is not going to help.

Update 2: I went to ~/bar.com.git/hooks and add a new file post-receive with the content:

#!/bin/bash

cd ~/bar.com
git pull ../bar.com.git master

and also chmod 755 post-receive, and if I edit a file on the local machine, and then git com -m "ok" and git push, it doesn't make the change go into the remote machine's folder ~/bar.com

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

网名女生简单气质 2024-11-10 05:46:54

您可以向~/bar.com.git 存储库。为此,请向 ~/bar.com.git/hooks/ 目录添加一个可执行文件 post-receive,其内容为:

#!/bin/sh

unset $(git rev-parse --local-env-vars)
cd ~/bar.com
git pull

确保 post-receive 文件具有可执行位(例如 755)。

现在,只要将某些内容推送到 ~/bar.com.git 存储库,~/bar.com 存储库就会自动更新。

另请参阅

了解为什么取消某些环境变量是必要的。

You can add a post-receive hook to the ~/bar.com.git repo for this. To do this add to the ~/bar.com.git/hooks/ directory an executable file post-receive with the content:

#!/bin/sh

unset $(git rev-parse --local-env-vars)
cd ~/bar.com
git pull

Make sure the post-receive file has the executable bits(e.g. 755).

Now whenever something is pushed to the ~/bar.com.git repo, the ~/bar.com repo is updated automatically.

See also

to understand why unsetting some environment variables is necessary.

笑脸一如从前 2024-11-10 05:46:54

我使用以下更新后脚本(确保在其上设置了可执行位):

#!/bin/sh
rm -rf ~/public_html/xxx
git-archive --format=tar --prefix=xxx master | tar x -C ~/public_html

它可以完成任务,但是当站点不可用时会有一个短暂的窗口。直接在您的 ~/bar.com 中执行 git pull 将暴露 git 的 .git 目录,因此请确保您在 http 服务器中阻止它,或者将 .git 保留在目录层次结构中更高的位置,即。像这样的东西:

~
 \
  - repo
    \
     - .git
     - bar.com
       \
        - your content

I use the following post-update script (make sure you set executable bit on it):

#!/bin/sh
rm -rf ~/public_html/xxx
git-archive --format=tar --prefix=xxx master | tar x -C ~/public_html

It does the thing, but there's a short window when the site is not available. Doing git pull directly in yours ~/bar.com will expose git's .git directory, so make sure you either block it in your http server, or keep .git somewhere higher in directory hierarchy, ie. something like:

~
 \
  - repo
    \
     - .git
     - bar.com
       \
        - your content
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文