我有一个git存储库,其中有一堆大型csv,我不想克隆,因此我遇到了git sparse-checkout和这篇文章:https://github.blog/2020-01-17-bring-your-monorepo-down-to-size-with-sparse-checkout/
在这篇文章中,我采取了以下措施:
git clone --no-checkout https://github.com/john_doe/repo-with-big-csv.git
cd repo-with-big-csv
git sparse-checkout init --cone
然后,我编辑
.git/info/sparse-checkout
并添加以下内容(改编自上一页中的example):/*
!**/*.csv
但它似乎无法正常工作。在
git pull
之后,某些文件夹被克隆,有些则没有。当我执行git sparse-checkout list
时,我还注意到一条警告:warning: unrecognized pattern: '**/*.csv'
warning: disabling cone pattern matching
/*
!**/*.csv
仅忽略特定文件类型的正确方法是什么?
最佳答案
请参阅“Git sparse checkout with exclusion”,并确保使用Git 2.26.x,它对 git sparse-checkout
command进行了一些修复。
When in cone mode, the git sparse-checkout set subcommand takes a list of directories instead of a list of sparse-checkout patterns
If
core.sparseCheckoutCone=true
, then Git will parse the sparse-checkout file expecting patterns of these types. Git will warn if the patterns do not match.
您只需要根据文件夹前缀匹配使用限制模式。
OP Frode Akselsen添加in the comments:
my example is actually working: the folders that don't show up just contain only
.csv
files, hence, after applying the rules in.git/info/sparse-checkout
, nothing is in the folder anymore and therefore Git doesn't show the folder.
我确认Git仅显示内容:如果文件夹中没有文件(没有“内容”),则该文件夹不可见。
关于linux - git sparse-checkout忽略特定的文件类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61623691/