Git稀疏检出只在存储库根目录下处理文件夹?

3

我们有一个包含许多项目的代码库。我只关心其中的“oracle”项目。然而,当我下载代码库时,我发现其他文件夹中都有名为“oracle”的子目录。是否有一种方法只获取匹配的父文件夹?

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

git config core.sparseCheckout true

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

输出

#ls -l
  oracle
  directory123
  directoryabc

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

1
如果oracle项目位于您的repo根目录下,我有一种感觉,写/oracle/而不是oracle/应该可以解决问题。 - jub0bs
好吧,那个可以工作!如果你愿意,你可以提交作为答案,我会接受。 - sdot257
1个回答

6
通过将 oracle/ 写入 $GIT_DIR/info/sparse-checkout,您告诉 Git 仓库仅填充工作目录中的文件(如果有)其父目录名为“oracle”。目录
oracle/
directory123/sub1/sub2/oracle/
directoryabc/sub1/sub2/sub3/oracle/

所有都满足这个条件。

如果你想将稀疏检出限制在位于 Git 仓库根目录下的 oracle 目录中,你需要将 oracle/ 改为 /oracle/(注意前导斜杠),写入到 $GIT_DIR/info/sparse-checkout 文件中。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接