Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to undo merge request with its commits?

I did a merge request to my branch develop on gitlab. Then I realise I had done a huge mistake. I quickly pushed the revert button, and I thougth It's everything ok, It wasn't. Gitlab made only revert commit. In the logs there are still commits from source branch. It causes many issues with version. Is it any way, any solution to revert single merge request on gitlab platform and clean branch logs from many commits which are unwanted. I'd like my branch to be like this merge request never had a place.

like image 666
gizyk Avatar asked Dec 12 '18 08:12

gizyk


1 Answers

First create a new branch keepsafe to have all those changes still somewhere in case you mess up. This will "copy" the current state locally and save it on the remote also.

git checkout -b keepsafe
git push

Now go back to develop. X is the number of commits you want to have deleted.

git checkout develop
git reset --hard HEAD~X
git push -f

The will hard reset local develop to the original commit. git push -f will overwrite the remote branch. All commits will be gone.

Note that GitLab allows the administrator to disable force pushes (git push -f), so if that doesn't work you need to talk to your administrator.

like image 125
mbuechmann Avatar answered Sep 29 '22 05:09

mbuechmann