2015-04-27 78 views
1

我有一个名为“测试”分支,和后收到钩写入主到活动目录,就像这样:怎么写一个特定分支到磁盘上后收到的git

#!/bin/bash 
cd .. 
env -i git reset --hard 

我不想用已经工作很长时间的现有进程破坏任何东西,但是当新的更改被推送到测试分支时,我想让git将分支的文件写入磁盘/ var/www /测试我已经得到了这个工作使用以下语法:

git clone foo foo-copy 
(cd foo-copy && git checkout branch) 

但这种操作方式太慢n在测试分支之上推送另一个提交,并且不会覆盖现有文件夹中的文件(尽管我认为我可能在那里是错误的)

tldr:如何将特定分支高效写入特定文件夹并在收到后覆盖?

回答

0

对于这一点,我认为

# one-time setup 
mkdir -p /var/www/testing 
git clone -s -b testing --single-branch myrepo /var/www/testing 

而在.git/hooks/post-receive(主回购)

#!/bin/bash 
while read old new refname; do 
     if [[ $refname == refs/heads/testing ]]; then (
       eval unset ${!GIT_*} 
       cd /var/www/testing 
       git fetch 
       git reset --hard origin/testing 
     ); fi 
done 

会做的伎俩。如果您删除主repo中的测试分支,删除不会影响克隆,它只会停止更新。

+0

啊谢谢,myrepo需要指出什么?回购的目录?或专门在回购中的.git文件夹? – arcanine

+0

看起来像它需要按照手册的repo文件夹,再次感谢你:) – arcanine

相关问题