[英]What happend to my changes after git stash push
我可以发誓git stash push
毁了我的工作。
这就是发生的事情。 今天早上做了大约两个半小时的工作,结果比预期的更复杂,我决定创建一个新的分支,在提交更改之前测试它所基于的分支。
所以,我保存了文件(一个 Jupyter Notebook)。 我运行git stash push -m "Move to new branch."
然后我创建一个新分支(使用 VSCode。)我签出新分支。 我运行git stash pop
并打开笔记本。
顺便说一句,在我什至注意到这些更改实际上不在 notebook 中之前,我立即将它们提交到新分支。 该笔记本似乎确实通过运行git stash pop
进行了修改,但最近没有任何更改。
这是 git pop 的输出,经过轻微编辑以删除实际的文件/分支名称...
On branch new_branch
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: notebook.ipynb
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (a9044f83c9bf2ef48182c8fbe0715dbabaa2f4fd)
无论如何, git stash
说“git-stash - 将更改隐藏在一个脏的工作目录中”,但我刚刚保存的更改都不在那里。
我错过了什么? 有什么方法可以恢复更改或被吃掉吗?
要查看运行git stash pop
时丢弃的git stash pop
,请检查终端中提到的提交e9044f83...
例如 :
# have a view of what files were "saved" in that commit :
git log --graph --oneline --name-status e9044f83
# check the content of 'notebook.ipynb' in that commit :
git show e9044f83:notebook.ipynb
# check the content that was *staged* when you stashed :
git show e9044f83^2:notebook.ipynb
如果文件中的更改不存在,也许您运行了git stash
两次,并且您要查找的文件的内容在较旧的 stash 中。 检查其他藏品:
# this will list the stashes you currently have :
$ git stash list
# 'git stash show' and 'git stash show -p' will show you what is stored
# in a given stash :
$ git stash show stash@{0}
$ git stash show stash@{1}
...
# 'git show [commit]:notebook.ipynb' will show you the content of that file :
$ git show stash@{0}:notebook.ipynb
$ git show stash@{1}:notebook.ipynb
...
运行git stash pop
,您的 stash 提交 ( a9044f83...
) 不再被任何内容引用,也不是 reflog 的一部分,因此 git 的垃圾收集可以比其他提交更快地收集它。
如果你想保留那个提交,创建一个指向它的引用(一个分支或一个标签,或者你喜欢的其他东西......)。 例如 :
# you will now have a tag named 'keepme' which points at that commit :
git tag keepme e9044f83
如果您要查找的更改不在存储中,则它们可能已提交到其他地方。 在这种情况下,请检查您的 reflog :
git reflog
并在那里搜索笔记本的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.