36

Is there a way to rebase a branch onto another while skipping a particular (conflicting) commit on the other branch?

For example, I want to rebase mybranch onto master, but master contains a commit that will conflict with the commits in master, so I prefer to undo that commit completely.

-o-o-o-o-o-x-o-o-o-o master
     |
     o-o-o-o mybranch

x marks the conflicting commit.

Phillip
  • 5,366
  • 10
  • 43
  • 62

1 Answers1

57

Use interactive rebase:

git rebase -i master

An editor will open and you will have a list of commits like this:

pick b8f7c25 Fix 1
pick 273b0bb Fix 2
pick 6aaea1b Fix 3

Just delete the commit you want to skip. It will be omitted while rebasing your branch onto master.

P.S. If you cannot see the editor, please, refer to this question for solution: How can I set up an editor to work with Git on Windows?

Community
  • 1
  • 1
Sergey K.
  • 24,894
  • 13
  • 106
  • 174
  • The editor only shows the commits on mybranch. Is there a way to bring it up showing all the commits; i.e. from the tip of mybranch, down to master, and up to the tip of master? – Phillip Sep 26 '12 at 15:26
  • 1
    Do you want to delete the commit in your branch or in master? The second option if pretty insafe and will cause troubles to all other developers who have ``master`` as their upstream. – Sergey K. Sep 26 '12 at 15:28
  • I want to skip a commit on master (I added a diagram as part of my question). I'm not worried at the moment about `master` on the upstream. – Phillip Sep 26 '12 at 15:38
  • 1
    When checkout master and do ``git rebase -i ^`` and remove it in the editor. – Sergey K. Sep 26 '12 at 15:39