git checkout . adds directories excluded by sparse checkout

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 19:56:25

问题


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
a b

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

git checkout .
ls
a b c

By the way:

git --version
git version 1.7.10.4

The question Why do excluded files keep reappearing in my git sparse checkout? is related, but much older and doesn’t quite describe what I’m seeing.


回答1:


It's not by design. The behavior has changed in Git 1.8.3.




回答2:


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.



来源:https://stackoverflow.com/questions/15251638/git-checkout-adds-directories-excluded-by-sparse-checkout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!