丢失的 git stash 更改
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12147042/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
lost git stash changes
提问by nids
So here's what happened: I was on a branch 'A' and did a Git stash on that branch. Then I switched to another branch 'B'. I navigated back to Branch 'A' but did not do a Git stash pop. I switched to the master branch and then back to branch 'A'. I am trying to go a git stash pop now but cant seem to get my changes back.. I need to recover that code but whenever I do a git stash pop, my file changes are not listed. I did not commit any code.
所以这就是发生的事情:我在一个分支 'A' 上并在那个分支上做了一个 Git stash。然后我切换到另一个分支“B”。我导航回分支“A”,但没有执行 Git stash pop。我切换到主分支,然后回到分支“A”。我现在正在尝试进行 git stash pop,但似乎无法恢复我的更改。我没有提交任何代码。
Is there a way to recover the changes that I made? would really appreciate any help in this regards.
有没有办法恢复我所做的更改?非常感谢这方面的任何帮助。
采纳答案by Adam Dymitruk
Stashes should be viewable via
应该可以通过以下方式查看隐藏信息
git stash list
or
或者
gitk --all
also, git stash
does not stash untracked files. If you did this and subsequently did a git checkout --force
of another branch to overwrite untracked files with tracked ones in another branch, you have lost that content. The recommended way to stash is with
此外,git stash
不存储未跟踪的文件。如果你这样做了,随后又做了git checkout --force
另一个分支的a来用另一个分支中的跟踪文件覆盖未跟踪的文件,那么你已经丢失了该内容。推荐的藏匿方式是
git stash -u
This will prevent losses of this type.
这将防止这种类型的损失。
回答by Puneet Behl
We also faced the same issue. So, here is how we recovered the lost changes:
我们也面临同样的问题。所以,这里是我们如何恢复丢失的更改:
Go back to branch B.
git checkout B
Use
git reflog
option to mange reflog information.git reflog --all
Output:
f332d5c refs/stash@{0}: WIP on B: aa1d0c1 xyz commit message
Now, switch to branch A using
git checkout A
Finally, to recover your lost changes.
git stash apply f332d5c
返回分支 B。
git 结帐 B
使用
git reflog
选项来管理 reflog 信息。git reflog --all
输出:
f332d5c refs/stash@{0}:B 上的 WIP:aa1d0c1 xyz 提交消息
现在,切换到分支 A 使用
git checkout A
最后,恢复丢失的更改。
git stash 应用f332d5c
回答by JohnnyFun
Something similar happened to me. In short, check to make sure you didn't accidentally push the new files to the other branch.
类似的事情发生在我身上。简而言之,检查以确保您没有意外地将新文件推送到另一个分支。
Here's what happened to me: I stashed my stuff, switched from 'dev' to 'master' to do a hotfix quick. When I pushed my hotfix to master, I didn't notice that I also added my new files that were meant for dev to the master branch--I too assumed stash included those files.
这是发生在我身上的事情:我把我的东西藏起来,从“开发”切换到“大师”以快速进行修补程序。当我将修补程序推送到 master 时,我没有注意到我还将用于 dev 的新文件添加到 master 分支——我也假设 stash 包含这些文件。