Essential Git for Scientists
  • Introduction
  • Basic Concepts
    • Version Control
    • Git
    • Repo
    • Commits
    • Branches
    • Remotes
    • GitHub
    • De-centralisation
    • Summary
  • Basic Operations
    • Install Git
    • Create a Repo
    • Make a Commit
    • Inspect a Previous Commit
    • Revert a Change
    • Make a Branch
    • Extend a Branch
    • Fast-forward merge
    • Resolve conflicts
  • Intermediate Concepts
    • Commits
    • Three Trees
    • Rebase
    • Fetch
    • Pull
    • Push
  • Advanced Concepts
    • Reset
    • Interactive rebase
    • Formatted patches
    • Blame
    • Stash
    • Log filter
  • Cookbook
    • Undo
    • Branches
    • Diff
    • Stash
    • Merge
    • Hooks
    • Squashing
    • Rebase
    • Interactive Rebase
    • LFS
    • Submodules
    • Remote
    • Force push
    • Identify merged branches
    • Formated patches
    • Apply patches
    • Interactive rebase
    • Squash commits
    • Pull rebase
    • Log
    • Blame
    • Biset
    • Reset
  • Exercise
    • Exercise 1
    • Exercise 2
Powered by GitBook
On this page
  1. Advanced Concepts

Interactive rebase

Interactive rebase is rebase while tidying up the branch. It's mostly the "tidying up" component that people will use it for.

Imagine you make a large number of commits in a rush, may be under the deadline's pressure. You later find out:

  • Some commits are not critical and can be omitted

  • Some commits should be merged into one.

  • Some commits have bad commit messages.

  • etc.

Command

It's still rebase, but with the interative flag

git rebase -i
git rebase -interactive

What this will do is to

  • list all commits in the branch to be rebased, and

  • ask you what to do for each of them. E.g. whether to use the original commit, or modify it, or delete it.

Options include:

# 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
# d, drop = remove commit

The default option is pick which means use the commit. If all commits are picked, the scenario reduces to a normal rebase. But you can choose to drop, edit or squash the commits, which normal rebase won't allow you to do.

PreviousResetNextFormatted patches

Last updated 1 year ago