标签云

微信群

扫码加入我们

WeChat QR Code

This question already has an answer here:

how do i revert all my files on my local copy back to a certain commit?

commit 4a155e5b3b4548f5f8139b5210b9bb477fa549de
Author: John Doe <Doe.John.10@gmail.com>
Date:   Thu Jul 21 20:51:38 2011 -0500

This is the commit i'd like to revert back to. any help would be a lifesaver!


WilliamPursell - Why did you delete your answer? Yours seems to be the one that is most sensible. After the reversion, the OP can commit and push (that is, he has a working repo). All the answers below put the repo in a state where nothing useful can be done with it.

2018年07月17日08分47秒

I have been using this approach but what do you need to do in order to safely be able to commit on another machine? (instead git pull -f origin master)

2018年07月17日08分47秒

Yet another wrong accepted answer on Stack Overflow... You can't commit these changes. See Commit and push changes after going back to a particular revision in the repository?

2018年07月17日08分47秒

jww The question is "How do you revert back to a certain commit" How is this answer wrong?

2018年07月17日08分47秒

You can't commit and push after you follow the advice. What good is a repo that you can't do anything with after the bad commits are backed out?

2018年07月17日08分47秒

You're making the assumption that the user has a remote repository that they are tracking and that they already pushed their bad commits to it.

2018年07月17日08分47秒

revert is not the correct command. revert applies a new commit that undoes a previous commit. It doesn't take a --hard option.

2018年07月17日08分47秒

Charles: Why it is not correct? it does take the --hard option

2018年07月18日08分47秒

Read the documentation, revert undoes the changes introduced by a single commit, it doesn't reset the index and working tree to a particular commit which is what the asker is looking for. That is what reset does. reset does take a --hard option.

2018年07月17日08分47秒

oops...yes a typo error

2018年07月18日08分47秒

Yet another wrong answer on Stack Overflow... You can't commit these changes. See Commit and push changes after going back to a particular revision in the repository?

2018年07月17日08分47秒