Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable sparse checkout after enabled?

Tags:

git

I enabled a sparse checkout

git init
git remote add <url>
git config --global core.sparseCheckout true
echo "assets" >> .git/info/sparse-checkout
git pull origin master

Git checked out only the assets folder for me

But now, I want to enable full branch checkout again (checkout folders/files), but it doesn't seem to work.

1) first I disabled config

git config --global core.sparseCheckout false

2) removed the entries in .git/info/sparse-checkout

But git didn't checkout any of the other folders/files for me, it seems it is sticking to 'assets' folder.

Could anyone tell me how can I reset/disable this sparse checkout without creating a new repo.?

like image 744
iampolo Avatar asked Mar 23 '16 23:03

iampolo


People also ask

How do you get out of sparse checkout?

If you get stuck, run git sparse-checkout disable to return to a full working directory. The init subcommand sets the necessary Git config options and fills the sparse-checkout file with patterns that mean “only match files in the root directory”.

How does Git sparse checkout work?

"Sparse checkout" allows populating the working directory sparsely. It uses the skip-worktree bit (see git-update-index[1]) to tell Git whether a file in the working directory is worth looking at. If the skip-worktree bit is set, and the file is not present in the working tree, then its absence is ignored.


2 Answers

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
like image 135
VonC Avatar answered Oct 02 '22 14:10

VonC


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.

like image 42
Sascha Wolf Avatar answered Oct 02 '22 14:10

Sascha Wolf