我第一次尝试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界面中的root用户时,它就在那里。但是我尝试了git pull origin clipping
并且没有把那个目录拉回到我的工作副本中。
编辑:我想出了如何恢复它。在TortoiseGit上下文菜单中,我选择了“Diff”,在列表中,已删除的文件被列为“缺失”。我全部选中它们,右键单击它们,然后选择“恢复”。仍然不知道为什么dir首先被删除了。
答案 0 :(得分:0)
我遇到了同样的问题,我巧妙地发现,在其中一个.gitignore文件中有一个条目,该条目在表单上被删除: 目录/ *或目录/ ** 只有当目录后面是通配符char时才会出现这种情况。
在我的案例中删除该行解决了问题(它不应该在那里)
我很抱歉,但我无法解释为什么git这样做,也许别人可以。
答案 1 :(得分:0)
仍然不知道为什么目录首先被删除。
可能的原因是设置了GIT_DIR
。
“ git stash apply
”失败
正确访问工作树,该问题已在Git 2.24(2019年第四季度)中得到纠正。
请参见commit dfd557c的Johannes Schindelin (dscho
)(2019年10月4日)。
(由Junio C Hamano -- gitster
--在commit 66102cf中合并,2019年10月11日)
stash apply
:即使在工作树的子目录中,也可以正确报告状态在设置
GIT_DIR
的情况下,当Git希望在工作树的子目录中生成子Git进程时,我们需要注意明确指定工作树的顶级目录,因为它无法被发现:
- 当前目录不是的顶级目录 工作树和
- 它也不在
GIT_DIR
的父目录中。这解决了以下问题:
git stash apply
在工作树的子目录中运行时会报告几乎所有已删除或未跟踪的内容。要确保我们不引入“逆向问题”,即,当定义了
GIT_WORK_TREE
而没有定义GIT_DIR
时,我们只需确保同时设置了这两个条件即可。