簡體   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