maan81 maan81 - 1 year ago 89
Git Question

Removing branch merged in history?

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

From something like :

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

to :

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

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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download