42839

git checkout . adds directories excluded by sparse checkout

Question:

In a sparse checkout scenario, the command git checkout . restores the directories that should be ignored. Is this by design, or a potential problem in Git? I’m using git checkout . to discard any changes I’ve made to my working copy -- is there another command that will do the same and not suffer from this problem?

Here’s a reproducible example:

rm -rf test git init test cd test for f in a b c; do mkdir $f touch $f/$f git add $f/$f git commit -m "added $f" done git config core.sparsecheckout true echo a > .git/info/sparse-checkout echo b >> .git/info/sparse-checkout git read-tree -m -u HEAD ls <blockquote> a b </blockquote>

So far, so good. Here's the problem:

git checkout . ls <blockquote> a b c </blockquote>

By the way:

git --version <blockquote> git version 1.7.10.4 </blockquote>

The question <a href="https://stackoverflow.com/questions/11148579/why-do-excluded-files-keep-reappearing-in-my-git-sparse-checkout" rel="nofollow">Why do excluded files keep reappearing in my git sparse checkout?</a> is related, but much older and doesn’t quite describe what I’m seeing.

Answer1:

It's not by design. The behavior has <a href="https://git.coe.so/git/commit/?id=08d595dc1cdf6f0d8e6022a69c4fcdd2fba628cf" rel="nofollow">changed</a> in <a href="http://permalink.gmane.org/gmane.comp.version-control.git/224297" rel="nofollow">Git 1.8.3</a>.

Answer2:

I’m pretty sure that is by design. You are actively ordering git to create all those file, so it does that. The correct command for going back to the state of the last commit is:

git reset --hard

That should also take your sparse checkout settings into account.

Recommend

  • Java for loop of threads starting together (almost same time)
  • How to initialise/wire beans in Grails Spock unit tests?
  • Upgrading Spock unit tests from Grails 1.3.9 to Grails 2.3.9. But edit() test is failing
  • Testing Service with SQL and dataSource
  • Is it possible to get all uibezerpath from uiview?
  • Make file Linking issue Undefined symbols for architecture x86_64
  • Oozie error while trying to execute “bin/mkdistro.sh -DskipTests”
  • Can't run docker on os X with boot2docker
  • Subclipse- update working copy
  • RenderScript implementation of BLAS?
  • RXTX gnu.io.PortInUseException: & WARNING: RXTX Version mismatch
  • declare a transaction in ejb 3.0
  • MS Access 2010: Adding transaction management into a form
  • Serializable transactions not protecting me from double inserts
  • Fragment already added IllegalStateException with only one copy of fragment
  • LibGit2Sharp log remote
  • How can I fast-forward a branch without checking it out
  • Problems assigning variables to SQLite Tuples
  • psycopg2.ProgrammingError: syntax error at or near “stdin” error when trying to copy_from redshift
  • How to prompt user that edits have been made upon changing pages or sorting in Kendo Grid
  • EOFError, what happen to my minitest selenium test? how to fix it?
  • Find symbol dependencies in source code [closed]
  • manupulating a string to create directories in unix
  • Gforce min not supported for character in data.table
  • Using Netbeans with Cygwin and SDL, including SDL.h creates strange error
  • calling a fragment from fragment
  • Entity Framework ObjectContext: Concurrency
  • Android mkdirs() sdcard do not work
  • How to add the custom button on google's(device) native application in android?
  • change search magnifying glass to UIActivityIndicatorView
  • Blackberry 6: how to detect a long click on track pad?
  • How to get links to open in the native browser in iOS Meteor apps?
  • Exchange data b/w iOS devices using Bluetooth 4.0
  • Eraser for UIBezierPath
  • Compare two NSDates in iPhone
  • Load html files in TinyMce
  • Angular 2 constructor injection vs direct access
  • Java static initializers and reflection
  • Android Google Maps API OnLocationChanged only called once
  • UserPrincipal.Current returns apppool on IIS