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.

  • Securely deploy public repo to remote VM from Travis CI?
  • Bitbucket Commit Push History
  • GIT - Fail to checkout to other branch when nothing to commit - when file is in gitignore
  • Can I squash _other peoples_ git commits in a submitted PR?
  • Why can't I do git diff on this specific commit?
  • When a commit to revision control requires a developer to change their own config
  • 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?

  • Why doesn't git merge changes when two branches are different but with no new commits in either branch?
  • Is there anyway to programmatically fetch a zipball of private github repo?
  • Setting up a git repo on my GoDaddy hosting plan
  • VSTS unprotect git branch
  • is there a simple way to know which files will be updated in the next 'git pull'?
  • How do I reverse a specific hunk of a commit in git?
  • 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.