Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

linux - git sparse-checkout ignore specific file type

I have a git repository with a bunch of large csv in them, which I don't want to clone, so I came across git sparse-checkout and this post: https://github.blog/2020-01-17-bring-your-monorepo-down-to-size-with-sparse-checkout/

From this post I took following:

git clone --no-checkout https://github.com/john_doe/repo-with-big-csv.git
cd repo-with-big-csv
git sparse-checkout init --cone

Then I edit the .git/info/sparse-checkout and add the following (adapted from example in page above):

/*
!**/*.csv

But it doesn't seem to work properly. After git pull some folders are cloned, some are not. I also noticed a warning, when I do git sparse-checkout list I get:

warning: unrecognized pattern: '**/*.csv'
warning: disabling cone pattern matching
/*
!**/*.csv

What's the proper way to ignore a certain file type only?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

See "Git sparse checkout with exclusion" and make sure to use Git 2.26.x, which has some fixes for the 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.

You need to only use restrict patterns based on folder prefix matches.


The OP Frode Akselsen adds 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.

I confirm Git will only show content: if folder has no file (no "content"), said folder is not visible.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...