我已经使用post-receive钩子为git repo设置了push-to-deploy,现在我需要以某种方式使其仅签出特定存储库目录的内容,如下所示:
repo.git/dir1/dir11 -> /var/www/html/site1
repo.git/dir2 -> /var/www/html/site2
我只想检出目录的内容,而不要检出完整的结构,所以最后我将得到以下内容:
/var/www/html/site1/"whatever is in dir1/dir11/ directory".
谢谢。
为您要以此方式维护的每个目标目录保留一个索引文件,并直接使用低级命令(如read-tree)。
# prefix the index paths with the repo's .git directory path
( export GIT_INDEX_FILE=site1.index
export GIT_WORK_TREE=/var/www/html/site1
git read-tree -um `git write-tree` commit:dir1/dir11
)
( export GIT_INDEX_FILE=site2.index
export GIT_WORK_TREE=/var/www/html/site2
git read-tree -um `git write-tree` commit:dir2
)
两棵树的git read-tree -um
是签出的基础,它假设您的索引是从第一棵树派生的,并像签出一样过渡到第二棵树(或快速合并),两者都执行相同的读树,但是merge会更新当前HEAD,在此checkout会将其切换; read-tree根本不处理引用。 除非您一直在对索引执行其他操作,否则写树只会吐出与上次读取树相同的树,或者吐出最初为空树的树。