2012-07-27 356 views
4

我有一种不好的感觉,我的工作已经失传。有没有办法让他们回来?git stash:我的目录中的文件去哪里了?

这里是什么,我做了一个要点:

# 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/[email protected]{0} (c8353a2223b73ceb9aa73fac64829919b68c86e9) 

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

$ git --version 
git version 1.7.11.3 

Unfortulately,我不认为foo/bar见过库/指数,因为我没有它在此之前运行任何git命令。

回答

4

您可以轻松地恢复丢失的藏匿处(您可以在屏幕上看到它的修订版)。但这是没用的。

git stash不保存新文件(foo /目录内容在你的情况下),但它在退出前确实有git reset --hard。并且恢复有效删除foo/的工作目录。

我建议使用某种删除的文件恢复工具。

P.S.发送一封关于这个到git邮件列表的电子邮件。他们说这是一个错误,因为git stash旨在成为一个安全的命令。但现在只需使用git stash -u。这种方式git保存到存储所有(甚至未跟踪)的文件

+0

*使用某种删除的文件恢复工具*似乎是最现实的选择。感谢您发送错误报告。干杯。 – antak 2012-07-31 00:57:25

+0

刚用git 2.2.1发现了这种行为。任何想法这个bug的当前状态是什么?我能够在邮件列表中找到一些提及([1](http://article.gmane.org/gmane.comp.version-control.git/202332/match=11680453),[2](http:/ /article.gmane.org/gmane.comp.version-control.git/205540/match=git+stash+data+loss),[3](http://article.gmane.org/gmane.comp.version- control.git/229703/match = git + stash + data + loss)),但不是如何解决。 (除了邮件列表,项目是否有任何类型的错误跟踪器?) – doctaphred 2015-03-12 21:34:20