0

I am aware that a very similar question has been asked before, but not only is the provided answer awful and doesn't answer the question, but it seems there is no consensus about the technique as well. And even after searching on the net in general there doesn't seem to be any solution that works.

So here is it again.

How to configure git sparse-checkout so that it checks out the entire repository, with the exception of a particular (top level) directory?

Directory is called Tests_NR in the example.

Please provide an example that works with git version >= 2.37.3, on Windows Server 2016.

If possible, it should not be required to checkout the entire repo beforehand. (And then remove the excluded dir). But rather suppose we start with a clone without working directory. (git clone <url> --no-checkout)

What I have tried:

Create a file named ignore.txt that contains:

/*
!/Tests_NR/

Then

> git sparse-checkout init
> type ignore.txt | git sparse-checkout set --stdin
> git sparse-checkout list
!/Tests_NR
*
> git checkout master

=> Did not work. The working dir only contains the top level files, and not any directory.


Update

Following @phd' s comment, this works for me in a Windows Powershell prompt:

> git sparse-checkout init
> git sparse-checkout set '/*' '!/Tests_NR/'
> git sparse-checkout list
/*
!/Tests_NR/

The following git checkout will effectively get everything except Tests_NR.

Be careful, that when used in a regular Windows cmd, this yields a different result and fails:

>git sparse-checkout init
>git sparse-checkout set '/*' '!/Tests_NR/'
>git sparse-checkout list
'/*'
'!/Tests_NR/'
Scrontch
  • 3,275
  • 5
  • 30
  • 45
  • `git sparse-checkout set '/*' '!/Tests_NR/' && git checkout master` works for me — the entire tree is checked out except one directory. `{ echo '/*'; echo '!/Tests_NR/'; } | git sparse-checkout set --stdin` also works. – phd Sep 22 '22 at 16:26
  • Easy to do with the old non-cone-mode sparse checkout, literally impossible to do the way you want with the new cone-mode. – torek Sep 23 '22 at 04:27
  • @phd Did you test it? What command line interpreter are you using? I realize this will strongly depend. Your first line works indeed on a Powershell prompt, it does not in a cmd prompt. The second doesn't work for either. But I have a one-line solution in a Powershell prompt now, which is what i need. Thanks! – Scrontch Sep 23 '22 at 08:54
  • @Scrontch I've tested it thoroughly. Worked for me. Debian 11 stable (bullseye), git version 2.30.2. – phd Sep 23 '22 at 09:14

0 Answers0