简体   繁体   English

恢复为特定的sha或commit

[英]Reverting to a specific sha or commit

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 want to 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? 有什么帮助吗?

I think you want to use git reset 3d5575f8e4c97ddab8ad5d540fee4664c04db75d . 我认为您想使用git reset 3d5575f8e4c97ddab8ad5d540fee4664c04db75d This will keep your working files as is, but reset your HEAD to the commit you specified. 这将使您的工作文件保持原样,但会将HEAD重置为您指定的提交。 Additionally, it should reset your index as well (clears out files you have selected to commit, add, remove, etc). 此外,它还应该重置您的索引(清除您选择提交,添加,删除等的文件)。

If you want to get rid of all the changes to your working files, use git reset --hard 3d5575f8e4c97ddab8ad5d540fee4664c04db75d . 如果要摆脱对工作文件的所有更改,请使用git reset --hard 3d5575f8e4c97ddab8ad5d540fee4664c04db75d

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只是创建一个新的提交,该提交会还原该提交的更改,这可能不是您想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM