I use git 2.40 and I have repo folder structure like this:
└── root_dir1
│ ├── dir11
│ │ └── file11
│ │
│ └── dir12
│ │ └── file12
│ │
│ └── file13
│
└── root_dir2
├── dir21
│ └── sub_dir21a
│ │ │
│ │ └── file21
│ │
│ └── file22
│
└── file23
I need to checkout:
- Files that are placed directly in root_dir1 (exclude all subfolders with all it's content) - file13 in my specific example.
- Files that are placed directly in root_dir2 and directly in dir21 subfolder (exclude all other subfolders with all it's content) - file22 and file23 in my specific example.
I've tried the following:
git clone --no-checkout --sparse repo_URL
git sparse-checkout set root_dir1 root_dir2
git checkout
After that I've edited .git\info\sparse-checkout and added some negative patterns:
/*
!/*/
/root_dir1/
/root_dir2/
#added some negative patterns
!/root_dir1/*/
!/root_dir2/dir21/*/
And finally I called git sparse-checkout reapply. But I've received a warning:
warning: unrecognized negative pattern: '/root_dir2/dir21/*' warning:
disabling cone pattern matching
Despite of this warning I got exactly the files that I needed - looks like it's working. But I'm curious what's wrong with my negative patterns? Why !/root_dir1/*/ is valid but !/root_dir2/dir21/*/ not? And why it is working correctly despite of that?
My understanding is that the expected patterns in cone mode are in the form (white lines added for clarity):
(this would be the result of running
git sparse-checkout add dirA/dirB/dirC)i.e. some directories where everything below is present (in this example
dirC) and all their parent directories are present with their files but not their directories (in this example the root directory,dirAanddirB)which is not what you have. To not get the warnings you would need:
which makes
git sparse-checkout reapplyworks without warning and leave you in cone mode:(tested with Git 2.42.0)