How to exclude a specific merged branch's commit from the master branch in Git?

737 views Asked by At

I have a master and a develop branch. Feature and hotfix branches are merged into develop, and from time-to-time develop is merged into master. Now i have a request to exclude a specific hotfix from the master branch. Is this possible somehow? It was a relatively old hotfix branch, so since then i have more than 30 merges into develop. Or i should just create a new branch, reverting the changes manually and merge it to master?

1

There are 1 answers

0
Marina Liu On

You just need to revert the commit which the old hotfix was merged into develop branch.

Assume as below graph, you the old hotfix you want to excluded on master branch is the commits from commit F to commit G.

A---B------------------I---…       master
     \                /
       C---D---E--…--H---…         develop
            \       /     \
             F--…--G        J--…   hotfix/feature

You use use below way to exclude the old hotfix on your master branch:

First, find the merge commit that the old hotfix merged into develop branch. As the merge commit H on develop branch.

Then revert the changes on your master branch:

git checkout master
git revert -m 1 <commit id for H>

Note: if there is conflicts when revert the merged changes, you can modify and save the conflict files, and you git add . and git revert --continue to finish the revert.