Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git revert back to certain commit [duplicate]

Tags:

git

revert

commit

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!

like image 768
David Avatar asked Oct 11 '22 15:10

David


People also ask

Can you go back to previous commit in git?

Git Undoing Return to a previous commit Any changes can be made into a proper branch using either branch or checkout -b . Beware: While you can recover the discarded commits using reflog and reset , uncommitted changes cannot be recovered. Use git stash; git reset instead of git reset --hard to be safe.

How do I revert a last 3 commit?

Thus, to return the repository to the state before these changes were done, we need to revert the multiple commits done. We can use the git revert command for reverting multiple commits in Git. Another way of reverting multiple commits is to use the git reset command.


2 Answers

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.

like image 434
Andy Avatar answered Oct 13 '22 03:10

Andy


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

like image 60
TheOneTeam Avatar answered Oct 13 '22 03:10

TheOneTeam