简体   繁体   中英

Git submodule prepare for sparse checkout

I have a submodule to be used with sparse checkout. Without sparse checkout I'd do

git submodule update --init <path/to/submodule>

but how to initialize the submodule repository empty without fetching it (or fetching it, but not checking it out) yet, so I can invoke

cd <path/to/submodule>
git config core.sparseCheckout true
cd <../../..>
echo <subdir-to-get> .git/modules/<path/to/submodule>/info/sparse-checkout

Unfortunately

git submodule init <path/to/submodule>

does not create the repository in .git/modules/<path/to/submodule> and the file <path/to/submodule>/.git .

You can try, as in here , to clone the submodule as normal repository first, and then use git submodule absorbgitdirs .

By cloning first with a depth of 1, you don't get too many data:

git clone --depth=1 --no-checkout an/Url <path/to/submodule>
git submodule add an/Url <path/to/submodule>
git submodule absorbgitdirs

Then, you can modify the .git/modules/<path/to/submodule>/info/sparse-checkout

git -C <path/to/submodule> config core.sparseCheckout true
echo 'foo/*' >>.git/modules/<path/to/submodule>/info/sparse-checkout

Finally, get only the files you want:

git submodule update --force --checkout <path/to/submodule>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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