37

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

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

所以,从我的本地机器上,我可以做一个

git push

它将推送到foo.com/~/bar.com.git远程机器上(完整路径是ssh://peter@www.foo.com/~/bar.com.git

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

(这与Cannot git clone a folder on a server and then edit and git push有关? 现在我可以ssh到foo.comcd ~/bar.com在那里等待,并在本地机器git pull之后git push随时执行,但拥有它会很好自动完成)

更新:如果您知道具体细节以及如何做,请仅发布答案。如果你用谷歌搜索并在这里发布第一个或第二个谷歌结果,它不会有帮助。

更新 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

4

2 回答 2

56
于 2011-04-24T09:25:05.977 回答
1

我使用以下post-update脚本(确保在其上设置了可执行位):

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

它可以做到这一点,但是当站点不可用时会有一个短窗口。git pull直接在你的目录中做~/bar.com会暴露 git 的.git目录,所以确保你要么在你的 http 服务器中阻止它,要么.git在目录层次结构中保持更高的位置,即。就像是:

~
 \
  - repo
    \
     - .git
     - bar.com
       \
        - your content
于 2011-04-24T09:56:57.697 回答