git revert back to certain commit
Solution 1
git reset --hard 4a155e5
Will move the HEAD back to where you want to be. There may be other references ahead of that time that you would need to remove if you don't want anything to point to the history you just deleted.
Solution 2
You can revert all your files under your working directory and index by typing following this command
git reset --hard <SHAsum of your commit>
You can also type
git reset --hard HEAD #your current head point
or
git reset --hard HEAD^ #your previous head point
Hope it helps
Solution 3
http://www.kernel.org/pub/software/scm/git/docs/git-revert.html
using git revert <commit>
will create a new commit that reverts the one you dont want to have.
You can specify a list of commits to revert.
An alternative: http://git-scm.com/docs/git-reset
git reset
will reset your copy to the commit you want.
Related videos on Youtube
David
Updated on July 08, 2022Comments
-
David almost 2 years
how do i revert all my files on my local copy back to a certain commit?
commit 4a155e5b3b4548f5f8139b5210b9bb477fa549de Author: John Doe <[email protected]> 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!
-
jww almost 8 years@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.
-
-
CB Bailey almost 13 years
revert
is not the correct command.revert
applies a new commit that undoes a previous commit. It doesn't take a--hard
option. -
TheOneTeam almost 13 years@Charles: Why it is not correct? it does take the --hard option
-
CB Bailey almost 13 years
-
Christophe De Troyer over 8 yearsI 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
) -
Andy over 8 years@ChristopheDeTroyer I don't follow your question.
-
Randy L about 8 yearsso this actually changes the history? if so i need to add it to my list of
git rebase
andgit commit --amend
-
Andy about 8 years@the0ther -- This doesn't change history, it just erases some of it. It's like going back in time. You don't change anything you just reset the point in time where you are at.
-
Randy L about 8 yearsThinking about it a little more and it would fall into the category of "changing history" especially if you follow it up with a forced push to the remote.
-
jww almost 8 yearsYet 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?
-
Andy almost 8 years@jww The question is "How do you revert back to a certain commit" How is this answer wrong?
-
jww almost 8 yearsYou 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?
-
Andy almost 8 yearsYou'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.
-
Mehdi Haghgoo over 6 yearsThis is a very bad approach. I just lost all my recent commits!
-
piersb over 6 yearsDownvoting because OP specifically says "revert back to", and revert has a particular meaning in git; a reset can break history on a push, while a revert won't.
-
JavaGeek over 4 yearsAfter 'git reset --hard <hash>' on your local, if you try to commit your latest changes to remote branch, you will most likely get an error indicating that 'Your branch is behind origin'. When that happens, you need to force the push using an f tag 'git push -f'
-
DawnSong almost 4 yearsSafer than
git reset --hard
, and the latter is cleaner. -
Stepan Yakovenko about 2 yearsgit revert would not work for merges