git stash:我的目录中的文件去哪了?

4

我有一种预感我的工作丢失了。是否有可能找回它们?

以下是我所做的事情的要点:

# Initially
$ git init -q
$ echo foo >foo
$ git add foo
$ git commit -m initial
[master (root-commit) 399ac4f] initial
 1 file changed, 1 insertion(+)
 create mode 100644 foo

# Work work work
$ rm foo
$ mkdir foo && echo bar >foo/bar

# This is where things went bad
$ git stash
Saved working directory and index state WIP on master: 399ac4f initial
HEAD is now at 399ac4f initial
$ git stash pop
Removing foo
# On branch master
# ...
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (c8353a2223b73ceb9aa73fac64829919b68c86e9)

# What happened to my work!?
$ find foo
find: foo: No such file or directory

$ git --version
git version 1.7.11.3

不幸的是,在此之前,我没有在 foo/bar 上运行任何 git 命令,因此它似乎从未看到过存储库/索引。

2个回答

4
您可以轻松恢复丢失的存储(您可以在屏幕上看到其修订版)。但是这没有用。 git stash不保存新文件(在您的情况下为foo/目录内容),但是它会在退出之前执行git reset --hard。这将恢复工作目录,有效地删除了foo/
我建议使用某种已删除文件恢复工具。
附言:向git邮件列表发送了一封电子邮件。他们说这是一个错误,因为git stash旨在成为安全命令。但现在只需使用git stash -u。这样,git会将所有(甚至未跟踪的)文件保存到存储中。

使用某种已删除文件恢复工具似乎是最现实的选择。感谢您发送错误报告。干杯。 - antak
刚刚在使用git 2.2.1时发现了这个问题。有没有人知道这个bug的当前状态?我在邮件列表中找到了一些提及它的信息(1, 2, 3),但不知道它是如何解决的。(除了邮件列表之外,这个项目是否有任何形式的bug跟踪器?) - doctaphred

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接