繁体   English   中英

Git 删除了所有跟踪文件中的所有更改

[英]Git removed all changed in all tracked files

我做了:

git add --all # success
git status # saw all my changes in staged area
git commit -am wip # failed because of some hooks (it was expected behavior)
# fixed the issue which causes the hooks to fail

然后:

~ git add --all
fatal: Unable to create '/Users/stavalfi/projects/dancer/.git/index.lock': File exists.

Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.

然后:

rm /Users/stavalfi/projects/dancer/.git/index.lock
git add --all
git status

最后一个命令只显示了我添加的新文件。

我丢失了所有跟踪文件中的所有更改。

该怎么办?

它当然应该。 通过运行git add --all ,您要求 git :

不仅在工作树有一个匹配<pathspec>的文件的地方更新索引,而且在索引已经有一个条目的地方更新索引。 这将添加、修改和删除索引条目以匹配工作树。

除非作为checkout命令的一部分运行的钩子对工作目录做了什么,否则运行两个git add --all之间的索引的 state 应该是相同的。 并且由此产生的commit应该产生相同的树。

但是,如果确实发生了某些事情,那么您很幸运。 git add将文件作为“blob”添加到 object 数据库中。 由于您没有提交该数据,因此它被视为垃圾,最终将被垃圾收集。 但在那之前,你可以恢复它。

找到这些的最简单方法是使用专用工具git-recover ,它可以为您找到这些未引用的 blob。

暂无
暂无

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

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