如何在git存储/ git存储弹出后恢复索引? [英] How to recover the index after a git stash / git stash pop?
问题描述
当您完成 git stash pop
,输出中的最后一行是:
Drops refs / stash @ {0}(ca82a6dff817ec66f44342007202690a93763949)
如果您失去了它,请参阅如何在Git中恢复被丢弃的存储?以查找提交哈希。
一旦你拥有哈希,或者:
-
删除所有当前更改(应用隐藏):
git reset --hard
然后使用它的id重新应用藏匿,这次有索引:
git stash apply ca82a6d --index
-
仅重置索引,这里的要点是将索引保存为隐藏的第二个父级:
git reset ca82a6d ^ 2。
最后注意点。如果不指定它,它也会将HEAD移动到索引处(索引将显示为提交)。在这种情况下,运行
git reset --soft HEAD @ {1}
将HEAD返回到其原来的位置。
After adding some changes to the index with git add -p, I then issued a git stash but forgot to add --keep-index. Then I stupidly did a git stash pop, and all my changes to the index were gone. Is there a way to recover the index to the state before the git stash?
When you've just done git stash pop
, the last line in the output is:
Dropped refs/stash@{0} (ca82a6dff817ec66f44342007202690a93763949)
If you've lost it, see How to recover a dropped stash in Git? to find the commit hash.
Once you have the hash, either:
Drop all current changes (applied stash):
git reset --hard
And reapply the stash using its id, this time with index:
git stash apply ca82a6d --index
Reset only the index, the point here is that the index is saved as a second parent of the stash:
git reset ca82a6d^2 .
Notice the dot at the end. If you don't specify it, it'll also move HEAD to the index (the index will appear as a commit). In this case run
git reset --soft HEAD@{1}
to return the HEAD to its previous position.
这篇关于如何在git存储/ git存储弹出后恢复索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!