Git clone leads to deleted & untracked files
It sounds like you've somehow loaded an empty index. The normal way this happens in with the command git read-tree --empty
, but that's not something you usually use/know as a new user of git.
Perhaps something went wrong with the clone. It's shouldn't be difficult to fix though, just run
git reset
and the index should be restored to the contents of the latest commit.
I was retrieving a huge project with very long paths. I forgot to set up Git to use long paths:
git config --global core.longpaths true
After this, the cloning went fine and the status clean.
This issue confuses not only the OP who "is new to git". It also scares the sh*t out of me, a considerable git verteran. :-)
Thanks for the hints from other answers here, I realize that it is caused by git happens to be NOT able to checkout some files whose names contains unsupported characters on current file system and/or OS. For example, I encountered this same error when I'm cloning a github wiki repo, some wiki pages happen to contain a :
in its file name, they can be cloned fine on my Linux box, but (at a hindsight) obviously not on my Windows box.
Understanding the root cause gives us a confident decision on how/whether we fix this problem:
- We can fix it in the repo by renaming those offending filenames into shorter and/or containing only usual alphabet.
- Or, technically we do NOT have to fix it at all. If those offending filenames were just fine on their targetting platform, and we are working on some other content of this repo, we can continue our work as usual; we just need to remember to NOT commit those missing files as a deletion. (Been there, done that; Don't try this at home.)