问题描述
我被建议设置在远程服务器上
foo.com/~/bar.com#活网页内容
foo.com/~/bar.com.git#裸露的回购
所以,从我的本地机器上,我可以做一个
git push
,它将在远程机器上推送至 foo.com/~/bar.com.git
路径是 ssh://[email protected]/~/bar.com.git
可以添加 hook ,以便在推送后,远程服务器将 cd〜/ bar.com
并执行 git pull
以便所有内容都被更新(与本地机器相同)?(无需为Mercurial运行 git update
)
(这与挂钩到〜/ bar.com.git
回购。为此,请在〜/ bar.com.git / hooks /
目录中添加一个可执行文件 post-receive
,并将其与内容:
$ b $ g $ rev $ git rev-parse - local-env-vars)
cd〜/ bar.com
git pull
确保 post-receive
文件具有可执行位(例如755)。
〜/ bar.com.git 回购,
〜/ 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
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
- getting "fatal: not a git repository: '.'" when using post-update hook to execute 'git pull' on another repo
- Git - post-receive hook with git pull "Failed to find a valid git directory"
to understand why unsetting some environment variables is necessary.
这篇关于如何设置Git钩子,以便在推送到ssh://[email protected]/~/bar.com.git之后,它将转到〜/ bar.com并执行git pull?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!