Undo a Git merge, but keep later changes, and rewrite history -


i have bunch of branches, each different features. i'll have branch "not_master" contains master+feature so:

(not_master)     a--b--c--d--e---m--x--y--z (feature a)           --h--i--j-/ 

sometimes want unmerge feature a, keep commits x,y,z in "not_master".

in other words, this:

(not_master)     a--b--c--d--e--x--y--z 

i see can git revert -m 1 m add commit end reverts changes, don't want since these commits haven't been published yet adding more commits makes history harder read.

others suggest doing git reset --hard m, dump changes of x,y,z. thinking wrong way? should git reset --hard m , cherry pick x,y,z?

git rebase want. git rebase -i <commit e> should work: open editor, , delete merge commit , save.

you should able directly specify rebasing x..z onto e, sorting out semantics of command-line bit hairy. if i'm reading man page right, should git rebase --onto <commit e> <commit m> not_master.

edit: tested , appears work:

mkdir foo; cd foo git init touch initial git add initial git commit -m 'initial' git checkout -b topic touch topic git add topic git commit -m 'topic' git checkout master touch master git add master git commit -m 'master' git tag pre_merge git merge topic git tag merge touch post_topic git add post_topic git commit -m 'post topic' git rebase --onto pre_merge merge master 

results in history of

initial -- master -- post topic  (master)       \        \-- topic                 (topic) 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -