【发布时间】:2019-10-14 02:16:15
【问题描述】:
我第一次尝试git stash save。它工作得很好。然后我尝试了git stash apply,当我未提交的更改被恢复时,另一个效果是我的工作副本根目录中的一个随机目录被删除了。我不知道为什么它选择了那个确切的目录,在根目录下还有很多其他类似的目录。
git stash save 输出:
Saved working directory and index state WIP on clipping: cfeac4b - applying the solution from http://stackoverflow.com/questions/40385482/why-cant-i-use-opengl-es-3-0-in-qt
HEAD is now at cfeac4b - applying the solution from http://stackoverflow.com/questions/40385482/why-cant-i-use-opengl-es-3-0-in-qt
缩短git stash apply 输出:
Removing debug_stencil_not_working/textureandlight.js
Removing debug_stencil_not_working/qtlogo.png
[... more removes here ...]
On branch clipping
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: documentation/textureSize_missing.txt
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
deleted: ../debug_stencil_not_working/qtlogo.png
deleted: ../debug_stencil_not_working/textureandlight.js
[... more deleted files here ...]
modified: main.cpp
modified: main.qml
[... more modified files here ...]
Untracked files:
(use "git add <file>..." to include in what will be committed)
../dbg_repeater/dbg_repeater.pro.user
debug_stencil_not_working/
[... more files and dirs here ...]
注意:被删除的目录是一个提交和推送的目录。它没有未提交的本地更改。
知道为什么这个随机目录被删除了吗?
另外,如何恢复这个目录?当我在 github Web 界面中浏览到根目录时,它就在那里。但是我尝试了git pull origin clipping,但它并没有将该目录拉回我的工作副本中。
编辑:我想出了如何恢复它。在 TortoiseGit 上下文菜单中,我选择了“Diff”,在列表中删除的文件被列为“丢失”。我选择了它们,右键单击它们,然后选择“还原”。仍然不知道为什么该目录首先被删除。
【问题讨论】:
-
鉴于您使用了
apply(不是drop),存储应该仍然存在,因此您可以使用git stash show来检查它,也许使用-p来查看详细的差异。这实际上只显示了工作树提交,而不是索引提交,所以如果你做了一些单独的暂存与脏工作树,可能需要另一个步骤。 -
@torek:谢谢,我应该在
git stash show的输出中寻找什么? -
查看是否有
Deleted 文件。如果此处没有显示,请尝试git diff --name-status stash^1 stash,它将存储对的基数 (stash^1) 与索引提交 (stash) 进行比较,并查看是否有任何 那些 显示为Deleted. -
@torek:好的,我几天前放弃了我在问题中提到的存储,所以我不能用它来检查这个。我再次尝试
git stash save,然后是git stash apply,但没有删除任何文件夹。所以我们不能重现这个。不过,我想知道为什么会发生这种情况。 -
你可能仍然能够找到它(Git 默认不会清除小于 14 天的对象,即使那样它也只会删除一次未引用的对象它运行修剪代码)但它可能不值得太努力搜索。如果您确实想搜索,请参阅
git stash文档末尾的建议。