Accidental Merge of a non-master branch to master and wants to delete the merge commit from history

Hello All,

I would like to seek your guidance regarding this matter where we accidentally merge a non-master branch to the master branch via merge request. We wanted to do a refresh of the history of the master by delete the history of the non-master branch that was merged to the master to do that we plan on

  1. cloning the repository on our local.
    git clone
  2. create a backup of the master branch.
    git checkout master_backup
  3. checkout master and checkout the original commitId before the merge request has been accepted.
    _git checkout -b <commit_id> _ old_master
  4. delete the master branch
    git branch -D master
  5. replace master branch with the old_master branch
    git branch -m master
  6. unprotect master branch using the Gitlab GUI.
  7. Force push the change back to the repository
    git push -f origin master
  8. reprotect the master branch using the Gitlab GUI.

A. What do you think of the steps that we are taking? Are there anything the we have missed that you could point? Is the right thing to do regarding this matter?

P.S. Gitlab has a revert feature but it keeps the history of commit which is not what we exactly wanted.

Your thoughts are much appreciated.

I think git reset --hard is what you want here, with the revision hash that you want to wind back to. Take a backup first.

The problem with this method is that you cannot push back to master once you’ve done a
git reset --hard since it requires you to do a git pull (which goes back to the latest commit on master branch) before you can do a push to master branch. What we want is delete the bad merge commit from the master branch entirely both from the local and the remote(gitlab) branch.