Interactively cherry-picking commits with rebase

I can’t seem to figure this Git scenario out after reading the man page and searching some of the questions here, so I hope some of you can help me out.

Here’s the situation. I’ve got two branches, let’s call them master and experimental, with the commit graph looking like this:

  • Linus talk - Git vs. data corruption?
  • How to get files and content by SHA of commit
  • git rebase after fixing conflict
  • How to handle Git continuous integration merge conflicts
  • removing broken names in Git (dropbox conflicted copy)
  • Delete large number of branches from remote
  • A---B---C---D  master
          E---F---G---H  experimental

    and I want to end up here:

    A---B---C---D---F---H  master
          E---F---G---H  experimental

    I could achieve this by successively cherry-picking all relevant commits from experimental, but I’d like to use git rebase -i to get a list of all commits and select the relevant ones. Is this possible?

  • Bitbucket cannot clone repository “fatal: early EOF fatal: index-pack failed”
  • Count the number of commits on a Git branch
  • Create Git commits and push to GitHub with Ruby
  • Creating a custom SMS/MMS app in Android - using Eclipse and GitHub - why so many unresolveds?
  • Git - How to check if anything in refs/for/refs
  • Using Git to Figure out How Long a Line of Text Has Been In a File
  • One Solution collect form web for “Interactively cherry-picking commits with rebase”

    It is possible, but first, mark your experimental branch with a new ‘tmp‘ branch:

    git checkout experimental
    git checkout -b tmp

    Then do your rebase:

    git rebase -i master

    And drop all the commits you don’t want.

    A---B---C---D---F'---H'  tmp
          E---F---G---H  experimental

    Finally, merge master to tmp

    git checkout -B master # reset master to tmp
    git branch -d tmp

    Since a rebase moves a branch, and since it is master that has to change, jthill points out in the comments the shortest solution:

    git checkout -B master experimental
    git rebase -i master@{1}

    See more on HEAD@{1} at:

    • “Reverting an interactive git rebase” and
    • “HEAD and ORIG_HEAD in Git”
    Git Baby is a git and github fan, let's start git clone.