Git sparse checkout to only honor a folder at the root of the repo?

时间:2016-04-15 15:02:09

标签: git sparse-checkout

We have a repo with a bunch of projects. I am only concern with the "oracle" project within the repo. However, upon pulling down the codebase, I found subdirectories called "oracle" within other folders. Is there a way to only grab the parent folder that matches?

git init <repo>
cd <repo>
git remote add -f origin <url>

git config core.sparseCheckout true

echo "oracle/" >> .git/info/sparse-checkout

Output

#ls -l
  oracle
  directory123
  directoryabc

#find . | grep "oracle"
  directory123/sub1/sub2/oracle
  directoryabc/sub1/sub2/sub3/oracle

1 个答案:

答案 0 :(得分:3)

通过将oracle/写入$GIT_DIR/info/sparse-checkout,您可以告诉您的Git仓库仅填充工作目录中的文件(如果有)其父目录被调用&#34;预言&#34; 。目录

oracle/
directory123/sub1/sub2/oracle/
directoryabc/sub1/sub2/sub3/oracle/

都满足这个条件。

如果要将sparse checkout限制在Git仓库的根目录oracle目录,则需要编写,而不是oracle/ ,但是/oracle/(注意前导斜线)到$GIT_DIR/info/sparse-checkout