
The same is sometimes needed when the branches are based of of different core versions. Git rebase -onto issue-X issue-YĬan again save the day. Now you work mostly on issue-Y, but now you work more on issue-X and for your personal merit decide to make the history a little nicer, so now issue-X has diverted. git rebase -i HEAD3 Right after executing this command, your favorite editor will open up and present the list of commits you just selected (by providing a base commit). Lets say you worked on issue-X and issue-Y and issue-Y is built on top of issue-X. the Drupal 8 core queue that depend on each other. This is super helpful when having to juggle several branches for e.g.

To get the old base just use the commit ID of the first commit that does not contain changes you made. You would now use with the new base: git fetch upstream So when you normally use: git fetch upstream it will open the editor and remove all commits that are NOT yours. In that case you will need to tell git to rebase which on what. It gets only problematic if the history diverges as happened above.
#Git rebase onto how to
Usually git knows - when you call rebase - how to rebase as it has a common history. (Note: cherry-pick now also supports commit ranges, so this can be further simplified.) The rebase way # And reset your work branch to the new work What you could do is to checkout the develop branch, reset it to the new version and cherry-pick your two commits: # Reset the develop branch For example, you would like to change the branch starting point from C to F and you would like to remove commit D from your next-feature branch. It grants you control over what and where is being rebased. Lets assume your branch is called 'work' and you based your work upon 'upstream/develop'. We can say that git rebase -onto in precise and elastic solution. So all that you want is to move your two commits onto the new base. "Upstream Commit: This is the last upstream commit and this is another upstream commit together in one." "Your Commit A" - "Your Commit B" - "Upstream Commit: This is the last upstream commit" - "Upstream Commit: This is another upstream commit"īut now the branch you based your work on squashed their work together or removed a file due to privacy concerns and now upstream has:

It happened! A branch - you had based your work - on has diverged upstream, but you still have work in progress, which you want to preserve. Note: The following is meant for an intermediate audience that is familiar with general rebasing in GIT Longer explanation That is what rebase -onto does: git rebase -onto


Here are different ways to use git rebase -onto. A-B-C-D master \ E-F-G feature* (current branch) Output This is the initial git history we will use as example. My “easy to remember” documentation: git rebase ] Input Original documentation: git rebase ] git rebase -root
