How to rebase over already rebased branch

My git branches look like this:

 \                    \-*-further_foo_fixes_that_depend_on_x
  \                    \-*-*-further_bar_fixes_that_depend_on_x

It ended this way, because I thought my branch implement_x would be merged upstream as it is, but I was asked to squash it to a single commit, thus implement_x_rebased. However, I already started several branches for further fixing and developing that depend on my work, while waiting for the implement_x to get merged.

  • Heroku: Using external mount in local filesystem
  • How do I split up a large Git branch into lots of smaller branches?
  • hg-git push silently fails
  • How significant is the bazaar performance factor?
  • Git could not unlink file during pull - how do I get out of inconsistent state of repository?
  • JavaScript dependency management without NodeJS
  • Now I’d like to rebase the further work on implement_x_rebased. I thought this was a no-op, since implement_x and implement_x_rebased were in the exactly same state – there would be no merge conflicts, just applying the changes between implement_x and further_foo_fixes_that_depend_on_x etc. on top of implement_x_rebased. However, it seems that git isn’t that smart, and it tries to rebase all the way from the base – introducing needless merge conflicts.

    I thought that the easy way out is rebase&squash the further fixes on implement_x and then stash them, and apply the stashes to implement_x_rebased, but I’m curious whether there is any proper way to make git realise that implement_x and implement_x_rebased are actually in the same state?

  • Git GC mechanism - does it matter if tag annotated or lightweight
  • GitHub Organization Pages without named repository
  • Cannot switch branches
  • How to name and retrieve a stash by name in git?
  • How do I make Git ignore symlink?
  • git rebase using sourcetree
  • 2 Solutions collect form web for “How to rebase over already rebased branch”

    This seems to be a task for the --onto option of git rebase.

    git rebase --onto implement_x_rebased implement_x further_bar_fixes_that_depend_on_x

    You may want to have look at the --onto example in the git rebase manual.

    One way to approach this would be to make implement_x and implement_x_rebased the same first, e.g.:

    git checkout implement_x_rebased
    git merge implement_x

    then merge in your further fixes in the normal way.

    The merge of implement_x should be a NOOP from a code point of view (check that git diff implement_x implement_x_rebased actually produces nothing), but you are recording the fact the two are merged, which will allow you to pull over everything else easily.

    If they aren’t quite the same, you may need the -s ours option. This records that a merge has been done without merging the code. USE WITH EXTREME CAUTION.

    Failing that, you can simply use git rebase to rebase the later branches onto implement_x_rebased.

    This is better than cherry-picking as
    a) you don’t need to cherry pick each individual commit, remember to get the order right etc.
    b) semantically, your git tree makes more sense afterwards

    Git Baby is a git and github fan, let's start git clone.