Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rolling back a remote Git repository

Tags:

git

I have a remote Git repository, and I need to roll back the last n commits into cold oblivion.

like image 759
Jake Avatar asked Feb 25 '09 23:02

Jake


People also ask

How do you Uncommit from a remote repo?

To undo the last commit from a remote git repository, you can use the git reset command. command. This will undo the last commit locally. command to force push the local commit which was reverted to the remote git repository.

Can we revert pushed changes in git?

Summary. If you want to test the previous commit just do git checkout <test commit hash> ; then you can test that last working version of your project. If you want to revert the last commit just do git revert <unwanted commit hash> ; then you can push this new commit, which undid your previous commit.


2 Answers

You can use git revert <commit>… for all the n commits, and then push as usual, keeping history unchanged.

Or you can "roll back" with git reset --hard HEAD~n. If you are pushing in a public or shared repository, you may diverge and break others work based on your original branch. Git will prevent you doing so, but you can use git push -f to force the update.

like image 120
elmarco Avatar answered Sep 24 '22 04:09

elmarco


elmarco is correct... his suggestion is the best for shared/public repositories (or, at least public branches). If it wasn't shared (or you're willing to disrupt others) you can also push a particular ref:

git push origin old_master:master 

Or, if there's a particular commit SHA1 (say 1e4f99e in abbreviated form) you'd like to move back to:

git push origin 1e4f99e:master 
like image 26
Pat Notz Avatar answered Sep 22 '22 04:09

Pat Notz