Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Revert commit on remote branch without force pushing

How can I revert some remote repository to an old commit without force pushing and losing history? I know I could do

git reset --hard <commit-hash>
git push -f origin master

but I don't have permissions to force push and I also don't want to lose the history.

I want to do this because I pushed some **** into my master branch and the automatically deployment deploys to production environment from this branch. I worked around it by creating a new branch and changed the deployment settings to use this one, but is there any option to just set the current state of the remote repository to an old commit in case this happens?

like image 726
bpoiss Avatar asked Mar 09 '16 07:03

bpoiss


People also ask

How revert commit from remote branch?

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.


2 Answers

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

https://git-scm.com/docs/git-revert

like image 147
Enrique Quero Avatar answered Sep 28 '22 03:09

Enrique Quero


As added in the comment above.

Check this out to get the full details:

How to move HEAD back to a previous location? (Detached head)


There is also the git revert which is not described in the above post.

git revert <commit>

git revert simply undoes the desired commit and undoes the changes made to this repo by adding a new "revert" commit.

enter image description here

like image 40
CodeWizard Avatar answered Sep 28 '22 04:09

CodeWizard