rebase reverted merged branch

One way to achieve this is to interactively rebase the topic branch and reword the first commit after branching out of master (e.g. git rebase -i HEAD~10 if you have 10 commits in the branch). This will rewrite sha's of all the commits inside the topic branch. Therefore you will be able to rebase the usual way with git rebase master.


The documentation (git help rebase) suggests that "git rebase --force-rebase" does just this -- but (Git 1.9.1) it doesn't. The documentation also suggests that "git rebase -i --no-ff" is equivalent to that command -- but it isn't: it does work.

Having cloned your gist, the commands:

  git checkout topic
  git rebase -i --no-ff --onto master 7b3af topic

produce the desired result, with new versions of the "third" and "fourth" commits on top of master, and topic pointing at the new version of "fourth". In the second command, the SHA 7b3af is the "second" commit, the point where topic was branched from.


You need to use --onto to prevent Git form trying to determine the appropriate unmerged commits on its own.

E.g. (with topic branch checked out):

git rebase --onto master <id-of-branch-point>

For <id-of-branch-point> you want the git merge-base of your topic branch and the commit on master before the merge that you reverted.

Edit

Re-reading your situation again, it might be a better if you fast-forward the topic branch to the point where you reverted the merge, then revert the reversion and fix the topic branch from that point. This way you won't get a repetition of all the commits in the original topic branch but with new ids in the final history of master. Whatever you do, you're going to end up with a history involving "do, undo, redo", but this way might be considered a cleaner history.

Tags:

Git

Merge