撤消git stash


335

我只是在一个尚未提交的项目中进行了存储。我藏匿之前有办法回到状态吗?我该怎么办?我关闭了终端,笔记本电脑也关闭了。我已经做了一些研究,似乎没有办法做到这一点。


相关帖子在这里
英国广播公司

Answers:


651

您可以运行:

git stash pop

它将保存您的更改。

如果要保留文件状态(暂存或工作状态),请使用

git stash apply --index

10
好吧,不完全是。它不会重置登台目录中的内容,因此您必须重新整理所有内容(如果您刚刚完成了复杂的git add -p
Nick

没为我工作。我收到一个错误:mymodule/MyClass.java: needs merge - unable to refresh index。使用git stash pop... 时,避免手动合并正是我的目标
TanguyP

救了我。我虽然所有的变化都消失了,并且再次需要所有东西。谢谢
Ankit Shah

@TanguyP那么您最后的解决方案是什么?
theonlygusti

118

git stash list 列出您的隐藏更改。

git stash show查看n以下命令中的内容。

git stash apply 应用最新的存储。

git stash apply stash@{n} 申请较旧的藏匿处。

http://git-scm.com/book/en/Git-Tools-Stashing


1
在“ git stash list”之后还进行“ git stash show”,只是为了完善这个答案,并更好地确定用n代替什么。原来,我从不再存在的文件中藏了东西!
JimLohse

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.