git 恢复到特定的 sha 或提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8161376/
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
Reverting to a specific sha or commit
提问by Oscar Godson
I'm trying to revert to a specific commit ( 3d5575f8e4c97ddab8ad5d540fee4664c04db75d ), but when i do:
我正在尝试恢复到特定的提交( 3d5575f8e4c97ddab8ad5d540fee4664c04db75d ),但是当我这样做时:
git revert 3d5575f8e4c97ddab8ad5d540fee4664c04db75d
it says:
它说:
fatal: 'revert' is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>' as
appropriate to mark resolution and make a commit, or use 'git commit -a'.
I don't care those changes, and I also wantto lose those changes, revert to that commit (soft revert, dont want to lose the files) THEN repull down changes. My local stuff is all messed up. Any help?
我不在乎这些更改,我也想丢失这些更改,还原到该提交(软还原,不想丢失文件)然后撤回更改。我本地的东西都搞砸了。有什么帮助吗?
回答by DanR
I think you want to use git reset 3d5575f8e4c97ddab8ad5d540fee4664c04db75d
. This will keep your working files as is, but reset your HEAD to the commit you specified. Additionally, it should reset your index as well (clears out files you have selected to commit, add, remove, etc).
我想你想用git reset 3d5575f8e4c97ddab8ad5d540fee4664c04db75d
. 这将使您的工作文件保持原样,但将您的 HEAD 重置为您指定的提交。此外,它还应该重置您的索引(清除您选择提交、添加、删除等的文件)。
If you want to get rid of all the changes to your working files, use git reset --hard 3d5575f8e4c97ddab8ad5d540fee4664c04db75d
.
如果您想摆脱对工作文件的所有更改,请使用git reset --hard 3d5575f8e4c97ddab8ad5d540fee4664c04db75d
.
回答by manojlds
You want to do:
你想做:
git reset 3d5575f8e4c97ddab8ad5d540fee4664c04db75d
This will "reset" you to the commit specify.
这会将您“重置”到提交指定。
git revert just creates a new commit which reverts the changes of that commit, which is probably not what you want.
git revert 只是创建一个新提交,该提交还原该提交的更改,这可能不是您想要的。