How to do it...

We will try to rebase our current branch, rebaseExample, on top of the origin/stable-3.1 branch by performing the following steps. Remember that Git will apply the commits that are not available on the branch we are rebasing to; so, in this case, there will be a lot of commits:

  1. Rebase the branch onto origin/stable-3.1 by using the following command:
$ git rebase --interactive origin/stable-3.1
  1. What you will see now is a list of all the commits you will be rebasing onto the origin/stable-3.1 branch. These commits are all the commits between the origin/stable-3.1 and rebaseExample branches. The commits will be applied from top to bottom, hence, the commits will be listed in reverse order—at least compared to what you would normally see in Git. This actually makes good sense. The commits have the keyword pick to the left and then the abbreviated commit hash, and finally the title of the commit subject.

If you scroll down to the bottom, you will see a list along the lines of the following:

pick 43405e6 My brand new fishtank
pick 08d0906 Feed the fish
# Rebase da6e87b..08d0906 onto da6e87b
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

So, if we only want our fishtank commits to be based on top of the origin/stable-3.1 branch, we should remove all the commits except for our two.

  1. Remove all the lines except for the two commits at the bottom; for now, leave pick as the keyword. Save the file and close the editor, and you will get the following message from Git:
Successfully rebased and updated refs/heads/rebaseExample.
  1. Now, with gitk, check whether we accomplished what we predicted. The next screenshot shows our two fishtank commits on top of the origin/stable-3.1 branch. The following screenshot is what we expected:
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.47.253