How to disable sparse checkout after enabled?

While VonC's answer is certainly correct and will help with the imminent problem, I feel the need to elaborate and explain the underlying issue.

Background

Git's sparse-checkout makes use of the skip-worktree bit, which basically tells git to consider the file in your working directory to be "up to date", regardless of the true state.

When using sparse-checkout git will apply this bit to all files which do not match the patterns described in your sparse-checkout file. When disabling sparse-checkout, or deleting the pattern file, this bits will still be set and the files won't return. You can read about it here.

As such you have to remove the skip-worktree bit manually from the files in question. The easiest approach certainly being the suggestions from VonC.

But why?

The reasoning behind this is quite simple. The skip-worktree bit is not exclusively used for sparse-checkout but it's rather a tool in git's toolkit. Other processes make use of the same bit, or a user might even use it own his own (personally I use it regularly to ignore changes to configuration files when debugging).


On a sidenote: You can actually get a list of the files which have been flagged with the skip-worktree bit, by using git ls-files -v. This will list all files under version control; the files with the skip-worktree bit are prefixed with a S.

If you only want to list the skip-worktree flagged files you can easily parse and grep the list with the following command: git ls-files -v | grep '^S' | cut -d' ' -f2.


Update with git 2.25+ (Q1 2020), as I mentioned in "Git sparse checkout with exclusion", you now have the git sparse-checkout command.

More precisely, as noted in Tao's answer:

git sparse-checkout disable

Disable the core.sparseCheckout config setting, and restore the working directory to include all files.
Leaves the sparse-checkout file intact so a later git sparse-checkout init command may return the working directory to the same state.


Original answer: 2016

You can see an example of "undoing" a sparse checkout in this script by Roscoe A. Bartlett:

git read-tree is important.

echo "Undoing sparse checkout"

# Get the full tree back
echo "*" > $SC_FILE
git config core.sparsecheckout true
git read-tree --reset -u HEAD

# Wipe out all traces of sparse checkout support
rm $SC_FILE
git config core.sparsecheckout false

The article "Adventures in Git - SparseCheckouts" by Rich Somerfield propose a similar option (also valid for submodules):

echo "/*" > .git/info/sparse-checkout
echo "/*" > .git/modules/<MODULEPATH>/info/sparse-checkout
git read-tree -mu HEAD
git config core.sparseCheckout false

braham-snyder adds in the comments that updating a .git/info/sparse-checkout (to checkout and track additional files) can be achieved with

git read-tree --dry-run HEAD

While it is still experimental as of git 2.27, there is now a command that handles this more transparently/intuitively:

git sparse-checkout disable

My understanding is that you shouldn't have to set core.sparseCheckout manually anymore, it should be enabled, configured and disabled using this new git sparse-checkout command.

https://git-scm.com/docs/git-sparse-checkout

Tags:

Git