infoclogged
infoclogged

Reputation: 4007

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 i.e everything is deleted and newly added again.

git ls-files

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

Upvotes: 2

Views: 1456

Answers (2)

nielswd23
nielswd23

Reputation: 1

I was running into this same issue. For me, the problem was the mac optimized storage setting. My mac was temporarily offloading files to iCloud, and git thought these files were deleted.

You can remove this setting by unchecking the "Optimize Mac Storage" option: System Preferences > Apple ID > iCloud > remove "Optimize Mac Storage" (as outlined here).

Upvotes: -1

Mark Adelsberger
Mark Adelsberger

Reputation: 45769

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.)

Upvotes: 6

Related Questions