需要帮忙,我搞砸了,请不要过于指责。
好的,这是我所做的。
git stash(暂存当前工作区)
对代码进行了一些更改。
再次执行 git stash
git stash apply(恢复最新的暂存版本)
是否有办法回到第一个 git stash 前的代码状态?
真诚感谢你们提供的任何帮助。
提前说声谢谢。
git stash list
<shows all the saved stashes>
git stash show 'stash{0}'
<displays changes in this stash>
<change index according to the one you want, 0 is the last saved stash>
git stash apply 'stash{0}'
<applies the stash>
请注意,应用或弹出Git存储只会更改工作目录和/或暂存区。它不会创建新的提交。因此,只需进行硬重置即可回到第一个存储之前的状态:
# from your branch
git reset --hard
话虽如此,如果您想保留自第一次存储以来的某些更改排列方式,那就是另一回事,并且需要更多的工作和思考才能完成。
注意:通常情况下,弹出Git存储是有风险的,因为如果在过程中出现问题,您无法重新应用相同的存储,因为它已经从堆栈中弹出。最好使用git stash apply
。
git reset $(commit-id-to-revert-to) --hard
。 - Daistash apply
会保留存储,而stash pop
则会丢弃它。 - Daigit stash list
命令查看您在stash中所保存的条目,并通过git show stash@{<要查看的stash条目编号>}
命令检查它们。 - Romain Valeri