is itself an optional command and if it is not specified, then git looks at the parent of the checked out branch which is the equivalent of entering master. In our case, an of B, C, D, or master will all result in commit B serving as the cut point. However, if is not an ancestor, then git backs up the chain from the specified commit until if finds a common ancestor with the checked out branch (and aborts if it can't find one). All commits after until the head of the checked out branch are the ones that will be moved. In the example I provided, this would be anything that isn't C, D, or master. If it is a commit that is an ancestor of the checked out branch, then it serves as the cut point. is special because it can mean two different things. To move the entire feature branch, you can not select X, Y, Z, or feature as the since those all are commits inside the group being moved. can be any commit that won't be contained in the string of commits being moved. When providing a branch name, you are simply specifying the head commit of that branch. is the commit we will attach our string of commits to. Note that you must have specified in order to specify or git will think you are specifying. If you've already checked out the branch you want to rebase, then you don't need this. is optional and all it does is checks out the branch specified before executing the rest of the command.
The basic form of the command we need, cribbed from the documentation, is: git rebase -onto ] Rebase Any String of Commits to a Target Commit If topic is not checked out, you simply append topic to the command (except the last one) like so: git rebase -onto B master topicĪlternatively, check out the branch first with: git checkout topic The correct command to answer the posted question could be any of the following (assuming branch topic is already checked out): git rebase -onto B master