简体   繁体   中英

Why is suddenly all the files in git marked deleted?

I have a huge project with multiple submodules. The only thing I did extraordinary today was

git reflog

And it returned a set of commits.

But now, when after a couple of hours, when I am about to commit some changes, the git status shows that all the files needs to be added again ie everything is deleted and newly added again.

git ls-files

returns nothing. What went wrong? And how can I fix it?

I've asked for clarification in the comments, so if what I've inferred here is wrong I'll update once that clarification is provided. But what it sounds like you're saying is, the working copies are all present, but git status maybe says something like

Changes to be committed

  deleted: file1
  deleted: file2
  ...

Untracked files

  file1
  file2
  ...

This would indicate that your index was somehow wiped out. That could potentially happen with some variation of git rm --cached or git reset maybe. Or it could be that somehow the .git/index file was simply deleted.

In any event, if that's the state of things, you can

git add .

in the root of the working directory and it should be ok. You would then be able to see a proper git status comparing your work-in-progress to the current commit.

(I am assuming you still have the intended branch checked out; you might want to check that. Keep in mind you want to be careful with any command that would affect the working directory at this time, as you have uncommitted changes and git can't help you recover them if they're lost before they're committed, unless you go ahead and stash them.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM