Search code examples
gitgithubmergegit-revert

How to correctly revert multiple merge to remote master


I have 5 branches master, branch-1, branch-2, branch-3 and branch-4.

I made some changes to branch-3 and merged to master and again did it twice, now I want to go back to the stage before all the 3 merge, I can checkout to that commit and create another branch which contains the data how I need it .

with

git checkout 1ba671a79a0cc57129768ce1ad0218e17841e4d9

and then

git checkout -b "experimental-branch"

I have all contents in the stage I want in experimental-branch but I want this in master branch. How I can do this ?

I want to reset my master to this commit "1ba671a79a0cc57129768ce1ad0218e17841e4d9" after that there are commits and merges which are not required.


Solution

  • If you really want to reset your master branch to this commit, then just use:

    git reset --hard 1ba671a7
    

    This will reset your master branch to this commit. But keep in mind this will rewrite the history of this branch. This means that it could cause problems for anyone else sharing the branch (I'm assuming that no one else is sharing at the moment).

    To push the updated master you will need to use:

    git push --force origin master
    

    to force the branch to the repository.

    If you are trying to revert commits on a publicly shared branch, you really should consider using git revert instead.