4

First, let me tell you that I have already checked all the similar threads and searched google to find what the problem may be, but no success. My problem is that I'm trying to use sparse checkout in git, but I get this error:

error: Sparse checkout leaves no entry on working directory

I have this 60GB repository, which I need to clone. I need only a part of it, so to save a disk space I wanted to use sparse checkout. This is what I do:

  1. mkdir repoDir
  2. git init repoDir
  3. cd repoDir
  4. git remote add origin <repo url>
  5. git config core.sparsecheckout true
  6. echo "some/dir/" >> .git/info/sparse-checkout
  7. git pull --depth=1 origin master

Note I add the remote without -f flag, so nothing is fetched.

The result:

error: Sparse checkout leaves no entry on working directory

I tried several things:

  • Instead of initialising new repo and adding the remote manually, I did git clone --no-checkout and then set up the sparse checkout. This didn't help as my git status showed as if I deleted all the files in my repo. The git pull origin master command results in the same error.
  • Tried all possible combination of paths in step 6, with preceding slashes, slashes after the path, stars, spaces between path and > or >>. Btw I'm confused what is the correct format here, from the comments on SO I see mutually exclusive ways of formatting this.
  • Tried to make sure my .git/info/sparse-checkout is ASCII, and has proper line endings as found here. This is probably only problematic on Windows, but I just checked this anyway.

My git version: git version 1.9.3 (Apple Git-50)

OSX Yosemite 10.10.2 (14C109)

lawicko
  • 7,246
  • 3
  • 37
  • 49
  • Is it possible that `some/dir/` just doesn't contain any tracked files? – Sascha Wolf Mar 04 '15 at 11:03
  • @Zeeker it turns out I was looking for the folder that doesn't exist. – lawicko Mar 04 '15 at 11:37
  • is there some way to get this to work in windows with mixed case directory names like "ExtendedBuildings/Localization/pt" ? I can see the data I want to pull on github, and in an earlier copy of the same project .. (in fact even in the current project), but it is not working still – roberto tomás Apr 07 '15 at 14:57

3 Answers3

3

It turns out that "some/dir/" was wrong, since I didn't have the repository I didn't know it's real structure. I was able to browse it through web interface but I just discovered the folders don't correspond exactly to the real repository folder structure.

Lesson for the future: make sure you know the folder structure before creating sparse-checkout file.

lawicko
  • 7,246
  • 3
  • 37
  • 49
0

The sequence of operations I wanted to follow is similar, namely the one suggested in this other post https://stackoverflow.com/a/13738951/5459638. I get the error message

error: Sparse checkout leaves no entry on working directory

when launching git pull <remote> <branch> with branch being master.

As @lawicko said, in the project webpage I can click my way to the subdirectory to be cloned and copy the URL of that page; ctrl+L ctrl+C makes doing this nice and quick. This URL has the form

https://gitlab.com/<username>/<project>/tree/master/<subdir>/<subdir> 

The part that my sparse-checkout file accepts is the children of master

<subdir>/<subdir>/

with the trailing slash.

As an alternative to the same aim, there is another path in the form <project>/<subdir>/<subdir> to the right of the drop-down menu for switching branches at the top of the webpage. In this case, I would have copied and pasted the children of <project> plus the trailing slash. And this path is not as easy to copy and paste as the URL is.

XavierStuvw
  • 1,294
  • 2
  • 15
  • 30
0

Note that if you are using sparse-checkout on windows, you may need to add core.protectNTFS false per https://github.com/git-for-windows/git/issues/2777

wdtj
  • 4,554
  • 3
  • 17
  • 20