简体   繁体   English

git仓库的Checkout子目录

[英]Checkout subdirectory of git repository

I have set up push-to-deploy for git repo using post-receive hook and now I need somehow make it to checkout only content of a particular directory of repository, like below: 我已经使用post-receive钩子为git repo设置了push-to-deploy,现在我需要以某种方式使其仅签出特定存储库目录的内容,如下所示:

repo.git/dir1/dir11 -> /var/www/html/site1
repo.git/dir2       -> /var/www/html/site2

I want to have only contents of directory checked out, not full structure, so at the end I would have the following: 我只想检出目录的内容,而不要检出完整的结构,所以最后我将得到以下内容:

/var/www/html/site1/"whatever is in dir1/dir11/ directory".

Thanks. 谢谢。

Keep an index file for each target directory you want to maintain this way and use the low-level commands like read-tree directly. 为您要以此方式维护的每个目标目录保留一个索引文件,并直接使用低级命令(如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
)

The two-tree git read-tree -um is the fundamentals of checkout, it assumes your index is derived from the first tree and transitions to the second as for checkout (or fast-forward merge, both do the same read-tree, but merge updates the current HEAD where checkout switches it; read-tree doesn't deal with refs at all). 两棵树的git read-tree -um是签出的基础,它假设您的索引是从第一棵树派生的,并像签出一样过渡到第二棵树(或快速合并),两者都执行相同的读树,但是merge会更新当前HEAD,在此checkout会将其切换; read-tree根本不处理引用。 The write-tree will just spit the same tree you last read-tree'd, or the empty tree initially, unless you've been doing other things to the index. 除非您一直在对索引执行其他操作,否则写树只会吐出与上次读取树相同的树,或者吐出最初为空树的树。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM