Home > database >  Why git sparse checkout result in fatal error?
Why git sparse checkout result in fatal error?

Time:09-23

This is my commands to git I am running in Windows to sparse checkout folders from repo:

git clone --verbose --filter=blob:none --no-checkout --depth 1 --sparse "https://user:[email protected]/organization/repo-name.git"

cd ./repo-name

git config core.sparseCheckout true

git sparse-checkout init
git sparse-checkout add /MainFolder !/MainFolder/Subfolder
git sparse-checkout add /AnotherFolder
...
git checkout --progress --force
...

and everything working perfectly on my machine (tm) but all the sudden it stop working on another Windows machine (in Powershell or CMD) with error:

fatal: specify directories rather than patterns.  If your directory starts with a '!', pass --skip-checks

I guess it is somehow in line: git sparse-checkout add /MainFolder !/MainFolder/Subfolder but what ?

After a lot of try/catches I found out that this command works OK:

git sparse-checkout add MainFolder

but this command (with slash before folder name)

git sparse-checkout add /MainFolder

result in error: fatal: specify directories rather than patterns (no leading slash)....

What I need to set/configure on second machine so it continue to work as on my machine (including !/folder exclusion patterns) ?

P.S. Both machines using git version: git version 2.37.1.windows.1


@torek gave a correct answer but I want to add from myself:

There was a mis-understanding of what mode of sparse checkout is used. What is written above is a pattern style - so to make it work I must disable cone style like this:

git config core.sparseCheckout true
git config --worktree 'core.sparsecheckoutcone' false

and then

git sparse-checkout init

or just use `set' command instead all configurations commands like this:

git sparse-checkout set --no-cone

anyway - I must disable cone mode so above git commands will work (including the special symbols to exclude folders: ! and other staff) Thanks @torek

CodePudding user response:

You're using the new cone mode feature of sparse checkout.

Sparse checkout has two modes now: pattern mode and cone mode. Pattern mode is the old mode and is what you were using. Cone mode is the new default. It is much faster (or supposed to be much faster) and pattern mode is now deprecated. However, cone mode is more restricted: there are some sparse checkout setups that are literally not possible in cone mode.

If you're not depending on pattern mode, you can simply leave out the leading slash.

For more information on this, see the git sparse-checkout documentation.

  • Related