简体   繁体   English

为什么突然将git中的所有文件标记为删除?

[英]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状态显示所有文件都需要再次添加,即所有内容都被删除并重新添加。

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 但是,听起来您的意思是,所有工作副本都存在,但是git status可能表示

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. 这可能会随着git rm --cachedgit reset某些变化而发生。 Or it could be that somehow the .git/index file was simply deleted. 或者可能是因为.git/index文件以某种方式被简单地删除了。

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. 然后,您将可以看到适当的git status将您的进行中的工作与当前提交进行比较。

(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.) (我假设您仍要签出预期的分支;您可能需要检查一下。请记住,由于此时您尚未提交更改且git可以,因此请谨慎使用此时会影响工作目录的任何命令。除非您继续将它们藏起来,否则如果您在实施之前丢失了它们,可以帮助您找回它们。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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