丢弃 Git Stash Pop
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20038056/
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
Discard Git Stash Pop
提问by jdog
I did a git stash pop and now I have a ton of conflicts. I had committed all my recent code before the git stash pop
, so is there a way to go back to the last commit and get rid of all the conflicts and code the git stash pop
injected?
我做了一个 git stash pop,现在我有很多冲突。我在 之前提交了所有最近的代码git stash pop
,那么有没有办法回到上次提交并摆脱所有冲突并编写git stash pop
注入的代码?
回答by MichaelMilom
This has already been asked and answered on stackoverflow (see How to revert Git repository to a previous commit?), but the simple answer is:
这已经在 stackoverflow 上被询问和回答(请参阅如何将 Git 存储库恢复到以前的提交?),但简单的答案是:
git reset --hard HEAD
This should take care of your problem. Note that this removes all uncommitted changes from the repository.
这应该可以解决您的问题。请注意,这会从存储库中删除所有未提交的更改。
Note that if there are conflicts, the stash is preserved. From the stash docs:
请注意,如果存在冲突,则会保留存储。从存储文档:
Applying the state can fail with conflicts; in this case, it is not removed from the stash list. You need to resolve the conflicts by hand and call
git stash drop
manually afterwards.
应用状态可能会因冲突而失败;在这种情况下,它不会从存储列表中删除。您需要
git stash drop
手动解决冲突,然后手动调用。
回答by Poppolopoppo
Reset can also be called on specific files :
也可以对特定文件调用重置:
git reset HEAD <filename>...
You can't hard reset a file though. But you can revert the changes with checkout afterwards :
但是,您不能硬重置文件。但是您可以在之后通过结帐恢复更改:
git checkout -- <filename>...
You stash will be preserved, as pointed out by Luke in MichaelMilom answer.
正如 Luke 在 MichaelMilom 的回答中指出的那样,您的藏匿物将被保留。
This is useful when you don't want to lose your un-committed local changes.
当您不想丢失未提交的本地更改时,这很有用。
回答by jscs
If you never want to see the work in the popped stash again, this is as simple as a hard reset:
如果您再也不想看到弹出存储中的工作,这就像硬重置一样简单:
git reset --hard HEAD
This tells git to ignore the fact that you have uncommitted changes in your working directory, and sets the working directory, the staging area, and head to the commit you specify -- in this case, the existing HEAD, that contains all the work you've just committed.
这告诉 git 忽略您在工作目录中有未提交更改的事实,并设置工作目录、暂存区和您指定的提交——在这种情况下,现有的 HEAD,包含您的所有工作刚刚承诺。