User Tools

Site Tools


git_rebase

This is an old revision of the document!


Overview

Simple and advanced examples of rebasing.

SYNOPSIS

$ git rebase [-i | --interactive] [<options>]
  [--exec <cmd>] [--onto <newbase>]
  [<upstream> [<branch>]]
  
$ git rebase [-i | --interactive] [<options>]
  [--exec <cmd>] [--onto <newbase>]
  --root [<branch>]
  -
$ git rebase --continue | --skip | --abort | --quit |
   --edit-todo | --show-current-patch

The fundamental rebase operation

Three components define a rebase:

  • the branch to be rebased
  • the amount of that branch to be rebased
  • the target commit onto which to rebase

Examples

Simple example

              A---B---C           topic
             /
        D---E---F---G             master

One of:

$ git checkout topic
$ git rebase master

or:

$ git rebase master topic
                      A'--B'--C'  topic
                     /
        D---E---F---G             master

Example requiring "--onto newbase"

        o---o---o---o---o  master
             \
              o---o---o---o---o  next
                       \
                        o---o---o  topic
$ git rebase --onto master next topic
                          o---o---o  topic
                         /
        o---o---o---o---o  master
             \
              o---o---o---o---o  next

Removing a sequence of commits

Given:

A <--- B <--- C <--- D <--- E <--- F  [HEAD]

we could remove C and D with:

$ git rebase --onto B D

to get:

A <--- B <--- E' <--- F'  [HEAD]
git_rebase.1554586377.txt.gz · Last modified: 2019/04/06 21:32 by rpjday