Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rollback to an old Git commit in a public repo

How can I go about rolling back to a specific commit in git?

The best answer someone could give me was to use git revert X times until I reach the desired commit.

So let's say I want to revert back to a commit that's 20 commits old, I'd have to run it 20 times.

Is there an easier way to do this?

I can't use reset because this repository is public.

like image 463
David Avatar asked Jan 05 '10 17:01

David


People also ask

How can I undo a specific old commit?

To undo changes associated with a specific commit, developers should use the git revert command. To undo every change that has happened since a given commit occurred, use git reset.


1 Answers

Try this:

git checkout [revision] . 

where [revision] is the commit hash (for example: 12345678901234567890123456789012345678ab).

Don't forget the . at the end, very important. This will apply changes to the whole tree. You should execute this command in the git project root. If you are in any sub directory, then this command only changes the files in the current directory. Then commit and you should be good.

You can undo this by

git reset --hard  

that will delete all modifications from the working directory and staging area.

like image 106
Alex Reisner Avatar answered Sep 30 '22 13:09

Alex Reisner