maan81 maan81 - 2 months ago 18
Git Question

Removing branch merged in history?

How could I remove a branch I had merged into master in the past ?

From something like :

master
... a---> b ---> c ---------> d -----> e ---> f ---> g ---> h
\ /
x ---> y ------> z
branch1


to :

... a---> b ---> c ---------> d -----> f ---> g ---> h
\
x ---> y ---> z
branch1


I want to undo/remove merging of a branch into master I had done sometime earlier.




I have tried out something like but am getting conflicts. Is it possible ?

# currently we are in <h> commit in master branch
git checkout master

# new temporary branch
git branch tmp_master

git checkout tmp_master

# reseting temp. branch to reqd. commit
git reset <d> --hard

# cherry-picking subsequent commits
git cherry-pick <f>..<h>


After it was done --as I had expected to do :

# change temp. branch to master branch
git branch -D master

git branch -m master

kfb kfb
Answer

git rebase --onto d e will remove e from the branch history of h. See here for more information.

Comments