git 恢复到本地提交?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6007855/
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
Revert to local commit?
提问by Skizit
I've pulled code down from my repo which has messed things up. I'd like to revert my entire project to my last local commit. How would I do this?
我已经从我的 repo 中提取了代码,这把事情搞砸了。我想将我的整个项目恢复到我最后一次本地提交。我该怎么做?
回答by Chris Rasys
This will reset everything to your currentcommit (getting rid of all changes, staged or otherwise:
这会将所有内容重置为您当前的提交(摆脱所有更改,分阶段或其他方式:
git reset HEAD --hard
This will reset everything to the previouscommit (also getting rid of all changes, staged or otherwise)
这会将所有内容重置为之前的提交(也会删除所有更改,暂存或其他)
git reset HEAD^ --hard
the ^ next to HEAD means onecommit before HEAD, HEAD being where you are currently. You can go two commits back by using ^^, or three with ^^^. Additionally you can use a tilde to specify the number of commits: ~3 for three commits back.
HEAD 旁边的 ^ 表示 HEAD之前的一次提交,HEAD 是您当前所在的位置。您可以使用 ^^ 返回两次提交,或使用 ^^^ 返回三次。此外,您可以使用波浪号来指定提交次数:~3 表示返回三个提交。
git reset HEAD~3 --hard
Also keep in mind that the --hard option means that these commands will throw away any changes you have that are not stashed.
还要记住,--hard 选项意味着这些命令将丢弃您没有隐藏的任何更改。
回答by Micha?l Witrant
回答by Karl
git pull
can fetch and merge multiple commits. To go back to your previous local state (rather than back n-commits) you can use the reflog. git reset --hard @{1}
git pull
可以获取和合并多个提交。要返回之前的本地状态(而不是返回 n-commits),您可以使用reflog。 git reset --hard @{1}