Search code examples
gitmergebranchgit-branchgit-revert

revert multiple branch merged to develop


So I have a branch named BRANCH_A and there is another branch named BRANCH_B which these two branchs merged to develop branch. Now something went wrong in BRANCH_A, it's looks like regression for some reasons, maybe bad merged, after this merge I had few minor commits also in BRANCH_A anyway I need to revert back BRANCH_A to a safe commit before this merged happened. I follow other similar issues posts in stack, and did this as below :

first inside BRANCH_A I create a backup branch :

git branch BACKUP_A

Then reset to SHA from yesterday, which is a commit just before that merged happened :

git reset --hard SHA

Then point the BRANCH_A to backup branch :

git reset --soft BACKUP_A

Then commit :

git commit -m "Revert to SHA id"

and pushed :

git push

This will revert to that commit, But the thing is, I still have other branch changes ( for BRANCH_B ) on that merge and this only revert back those minor commits that I did after merge.

How can I revert in a way that I get raid of those changes from other Branch ( BRANCH_B ) and only keep changes that I actually did in BRANCH_A ( the commit before merge ) .


Solution

  • So I was able to fix this issue by doing these :

    Inside the branch_a that have issue :

    Git reset —hard commitID
    Git merge origin/develop
    Git push -f
    

    Then checkout develop and delete the branch_a

    git checkout develop
    git branch D branch_a
    

    And checkout it again

    git checkout branch_a
    

    Hope it works for someone who face similar issue.

    Note : Be careful when you run Git push -f because if you made a mistake you will loose your code