History
Interactive rebase
14 min read
Interactive rebase tidies up a sequence of commits in one go. It's how you make a branch presentable before the merge request: fold the "fix typo" into the commit it fixes, drop the debugging commit that shouldn't have gone in, change the message of a "WIP" and put the commits in an order that tells the story of the change.
In Versora you build the plan on a screen, see the result beforehand ("5 commits → 3 after the
rebase") and run everything in a single git rebase -i, with no text editor and no to-do list to
edit by hand.
- The menu of a commit on the current branch › Interactive rebase of the N commits above this one… (with only one commit: Interactive rebase of the commit above this one…). The commit you clicked is the base: it doesn't change, and the commits above it, up to HEAD, go onto the screen. To take the whole branch, right-click the commit it branched off from.
- The menu of a commit that isn't on the current branch › Interactive rebase of feature/login onto this commit…: the commits of the current branch go on top of that commit, and you choose what to do with each one along the way.
- The menu of another branch (a label in the graph or a row in the left panel, local or remote) › Interactive rebase of feature/login onto main…, right below Rebase feature/login onto main.
- The multiple selection menu (Ctrl+click or Shift+click on commits in the graph) › Interactive rebase of N commits…: the screen opens from the oldest commit in the selection up to HEAD, with the chosen ones highlighted ("the 2 selected commits are highlighted; the ones after them are included because they get rewritten too"). When the selection doesn't work, the item says why: "some commits aren't on feature/login", "there's a merge in the range", "the selection includes a stash" or "an operation is in progress".
- Palette and shortcut: there's no palette command to open the screen; use one of the menus above.
On the commit that is HEAD itself, the item shows up disabled: "Interactive rebase from this commit — there are no feature/login commits above it". If there's a merge between the commit you clicked and HEAD, the reason is "there's a merge above it".
- Header: the title says what is going to happen. "Interactive rebase of feature/login" when the commits stay where they are (the base is already an ancestor of the branch). "Interactive rebase of feature/login onto main" when the branch goes on top of another point. Below it, the range: "5 commits above main", "4 commits from feature/login that aren't in main" or "12 commits, from the first one on the branch".
- Buttons: Cancel, Reset list ("Sets every commit back to “Pick”, in the original order") and Start rebase ("Runs all the actions at once"). When the commits stay in place and nothing changed in the plan, Start rebase is disabled ("Nothing has been changed yet"). In a rebase onto another branch, it works even with everything on Pick: then it's a regular rebase.
- Summary strip: how many commits remain and what changes, with badges such as "1 new message", "2 squashed", "1 dropped", "1 edit stop" and "order changed". When something prevents the rebase, the reason shows up there, and the Start rebase button is disabled.
- List: the newest commit is at the top, as in the graph. Each row has the drag handle, the action selector, the SHA, the title, the author, the date and the move arrows. A commit that is already on the remote gets the on remote badge ("This commit is already on a remote branch: rewriting it will require a force push").
- Base line, at the end of the list: "base: main (f0e1d2c) — commit title · unchanged", or "start of history" when the rebase goes all the way to the first commit.
- Message panel, at the bottom: the message the commit in focus will have at the end.
- Footer: the key reminder and the rule "Newest at the top; squash and fixup fold a commit into the one below."
The right panel follows the row in focus, as in the graph: the commit's author, description and changed files.
Each commit gets an action in the row's selector (or by key, with the row in focus):
| Action | Key | What happens | Name in git |
|---|---|---|---|
| Pick | P | The commit is reapplied as it is. It's everyone's initial action. | pick |
| Reword | R | The commit stays the same, with the message you write in the panel below. | reword |
| Edit (stop to amend) | E | The rebase applies the commit and stops, so you can change its contents. The row gets the "stops here" badge. | edit |
| Squash into previous | S | The commit is combined with the commit below (the previous, older one). The changes and messages of both add up, and you can edit the final message. | squash |
| Fixup (discard message) | F | Like squash, but this commit's message is discarded: the message of the commit below stays. | fixup |
| Drop | D | The commit leaves the branch. Its changes no longer exist on the branch. | drop |
Squash and fixup always combine the commit with the one below. Several commits in a row on squash or fixup all land in the same picked commit right below them. The row being combined shows an arrow going down to the commit that receives it, and the receiving commit shows how many were combined into it (for example "+2").
Example: the feature/login branch has five commits above main, from newest to oldest:
e5f6a7b WIP
d4e5f6a Fix typo on the login screen
c3d4e5f Add debug logging
b2c3d4e Validate email on login
a1b2c3d Add login screen
You want to fold "Fix typo" into "Add login screen", drop the debug logging and give "WIP" a real message.
- In the graph, right-click the
maincommit the branch came from and choose Interactive rebase of the 5 commits above this one…. The screen opens with the five commits on Pick. - Click
d4e5f6a Fix typo on the login screenand press Alt+↓ twice. It moves down until it's right abovea1b2c3d Add login screen. - With it in focus, press F (or choose Fixup (discard message) in the selector).
The arrow shows up linking it to
a1b2c3d. - Click
c3d4e5f Add debug loggingand press D. The panel below shows "c3d4e5f will be dropped". - Click
e5f6a7b WIPand press R. In the panel below, replace the message with "Add the remember-me option to login". The row then shows the new title, with "was: WIP" next to it. - Check the summary strip: "5 commits → 3 after the rebase", with "1 new message", "1 squashed", "1 dropped" and "order changed".
- Click Start rebase. The "Start interactive rebase" confirmation sums up the plan: "5 commits become 3 on feature/login. The changes from 1 dropped commit will no longer exist on the branch ("Add debug logging")." and the rewrite warning. Confirm with Start rebase.
- At the end, the "Rebase complete: 5 commits became 3." notice appears, and the selection moves to the new tip of the branch.
- Drag: grab the row by the handle (or by any point that isn't the selector or the buttons) and drop it. An insertion line shows whether the commit will go above or below the target: on the top half of the target, above; on the bottom half, below.
- Row arrows: Move up (Alt+↑) and Move down (Alt+↓).
- Keyboard: ↑ and ↓ choose the commit; Alt+↑ and Alt+↓ move the commit in focus.
On the screen, "up" means "newer": the commit is then applied after the ones left below it. When the order changes, the summary strip shows "order changed".
The panel below shows the message the commit in focus will have after the rebase:
- Commit on Pick, with nothing combined into it: "Original message.", read-only. The Edit message button changes the action to Reword and puts the cursor in the text.
- Commit on Reword: the text is editable. If you change something, the Restore button ("Go back to the automatically built message") undoes your edit.
- Commit receiving a squash: the panel's title becomes "Final message of a1b2c3d + 1 squashed commit", and the text starts with everyone's messages, in order, separated by a blank line. It's editable.
- Commit receiving only fixups: "This commit's original message is kept."
- Row on squash or fixup: the panel shows the message of the group it's combined into, with the note "d4e5f6a is squashed into this commit".
- Row on Edit (stop to amend): "The rebase stops after this commit so you can change it." That commit's message is adjusted at the stop itself.
- Row on Drop: "c3d4e5f will be dropped. Its changes will no longer exist on the branch."
When the final message changes the title, the list row already shows the new title, with the old one in "was: …". An empty final message prevents the rebase: "The message of commit a1b2c3d is empty."
Use Edit (stop to amend) when the commit's contents need to change, for example to remove a file that went in by mistake.
- Mark the commit with Edit (stop to amend) and start the rebase. The confirmation warns: "The rebase will stop at the commit marked “Edit (stop to amend)”; continue from the changes panel."
- The rebase stops right after applying the commit. The notice says where ("The rebase stopped at "a1b2c3d Add login screen" so you can edit the commit."), the graph's WIP row shows "edit: a1b2c3d Add login screen" and the changes panel shows the "Rebase in progress" bar.
- Change the files and stage what should go into the commit.
- Click Continue on the bar. What is staged goes into this commit, and the remaining steps (including the new messages) are applied next.
Unstaged changes prevent continuing: "There are unstaged changes. Stage what should go into the commit — and discard or stash the rest — before continuing the rebase."
To split a commit into several, the dedicated feature is Split commit…, from commit surgery.
If a commit doesn't apply cleanly in its new position, the rebase stops:
- The notice says where: "The rebase stopped at a conflict in "b2c3d4e Validate email on login"." and tells you to resolve each file in the "Conflicted" section in the conflict editor and then click Continue.
- Continue goes on from where it stopped, applying the remaining commits and messages.
- Skip leaves the current commit out and goes on.
- Abort undoes the whole rebase: the branch goes back exactly as it was.
The bar, the buttons and the conflict editor are explained in Operation in progress and The conflict editor.
You can also continue from the terminal (git rebase --continue): the plan travels with the
rebase, so the new messages are applied just the same.
| Option | What it does | Default |
|---|---|---|
| Each commit's action | Pick, Reword, Edit (stop to amend), Squash, Fixup or Drop | Pick |
| Order | The order in which the commits are reapplied | The original order |
| Final message | The text of each commit that stays, when the action allows editing | The original one (or the combined messages, in a squash) |
| Reset list | Sets every commit back to Pick, in the original order, and erases the messages you wrote | — |
The plan becomes a single git rebase -i. Versora plays the role of the to-do list editor
(GIT_SEQUENCE_EDITOR): it checks that the list git built has the same commits the screen showed
and replaces it with the plan's list. No editor window opens.
git -c rebase.abbreviateCommands=false -c rebase.updateRefs=false \
-c rebase.missingCommitsCheck=ignore -c rebase.rebaseMerges=false \
rebase -i --autostash --no-autosquash --empty=drop --no-fork-point <base>
# rebase from the branch's first commit: ... rebase -i ... --root
For the example above, the to-do list is equivalent to:
drop c3d4e5f Add debug logging
pick a1b2c3d Add login screen
fixup d4e5f6a Fix typo on the login screen
pick b2c3d4e Validate email on login
pick e5f6a7b WIP # followed by an exec step that writes the new message
Details that change the result:
- New messages (Reword and squash) don't go through git's editor. Each one is kept in a file
inside
.git/versora-rebase/, and anexecstep right after the group applies it withgit commit --amend --no-verify --allow-empty --cleanup=verbatim -F <file>. Squash and fixup both becomefixupin the list; the difference is only in the final message. --autostash: uncommitted changes go into a stash first and come back at the end.--empty=drop: a commit that becomes empty in its new position (its content is already in the base) disappears, instead of stopping the rebase.- Rebase onto another branch: the commits whose content is already in the base are left out of the list, as git itself does.
rebase.updateRefs=false: other branches pointing to commits in the range stay where they are. If the branch is part of a stack, Versora tells you afterwards and offers Update the stack (see Branch stacks).- Pushed commits: the on remote badge marks the commits that are already on some remote
branch (
git rev-list <range> --not --remotes). - Merges: the plan is a simple sequence. A merge commit in the range prevents the interactive rebase.
- Before starting: Cancel closes the screen. If you had already changed the plan, it asks ("Cancel interactive rebase": "The plan you built on this screen will be lost. Nothing has changed in the repository.") and confirms with Discard plan.
- A rebase that finished without stopping: Ctrl+Z ("Undo: Interactive rebase") takes the branch back to where it was, with the old commits. Because undo also restores the files, it requires a clean working directory: "There are uncommitted changes. Stash or commit them before undoing this operation."
- A stopped rebase (conflict or stop to edit): Abort undoes the whole rebase. While it's stopped, Ctrl+Z doesn't undo the rebase: "A rebase is in progress. Finish or abort it (in the changes panel) before undoing." It only undoes the steps taken during the stop, such as saving a file in the conflict editor.
- A rebase that stopped and was continued until the end (with Continue or Skip, or even from the terminal): when it finishes, it goes into Ctrl+Z as a whole, as "Undo: Interactive rebase", and takes the branch back to where it was before you clicked Start rebase. The steps taken during the stops leave the undo history at that point. The previous point also remains in the branch's reflog, in case Ctrl+Z refuses (for example, because the repository changed afterwards).
- "This rewrites history: the commits involved get new SHAs. If they're already on the remote, you'll need to force push.": the confirmation's warning when no commit was pushed. With pushed commits, it says how many and reminds you that anyone who already pulled those commits will have to adjust.
- "2 commits are already on the remote: you'll need to force push": shows up on the summary strip. After the rebase, send it with Force push… (Force push).
- "a1b2c3d is the oldest commit being kept: there's no earlier commit for it to be squashed into. Choose another action for it or move it up.": a squash or fixup was left with no picked commit below it. The row gets the "no earlier commit" badge.
- "The message of commit a1b2c3d is empty.": write the final message in the panel below.
- "The branch has changed since this list was built.": another program (or another operation in the app) touched the branch. Click reload the list to build the plan again.
- "There's an operation in progress in this repository." (on the screen) or "There's an operation in progress. Finish or abort it before starting an interactive rebase." (when opening): finish or abort the stopped merge, rebase, cherry-pick or revert.
- "The range contains 1 merge commit (f9e8d7c "Merge branch 'main' into feature/login"). Interactive rebase works on a simple sequence of commits and would undo that merge. Choose a starting point above the merge, or use a regular rebase.": choose a base above the merge.
- "There are no commits to rebase: the current branch has nothing beyond the chosen point.": the chosen point is already the tip of the branch.
- "There are 1200 commits in the range; interactive rebase accepts up to 1000. Choose a more recent starting point.": the screen's limit is 1000 commits.
- "The branch has changed since the list was built. Reopen the interactive rebase.": HEAD changed between building the screen and starting.
- "Dropping every commit since the root would leave the branch with no history.": in a rebase from the first commit, at least one has to stay.
- "Your uncommitted changes were stashed before the rebase, but they couldn't be reapplied without conflicts. They're in the most recent stash.": apply the stash whenever you want (see Stash).
- "There are unstaged changes. Stage what should go into the commit — and discard or stash the rest — before continuing the rebase.": shows up when you click Continue at a stop to edit.
- "versora: group 2 has no commit of its own; the message was not applied": shows up in git's output when, at a conflict, you skip the commit that would receive a squash. The following commits go in as regular commits, and that group's combined message isn't applied.
- The screen's keys (P, R, E, S, F, D and Alt+↑/Alt+↓) can be changed in Preferences › Keyboard shortcuts: search for "Interactive rebase" (the actions "Interactive rebase: pick", "Interactive rebase: reword", "Interactive rebase: move the commit up" and so on, which apply "In the interactive rebase"). See Keyboard shortcuts.
- No company policy key changes interactive rebase.
- Edit message, drop and move commits: the same edits for a single commit, straight from the menu.
- Commit surgery: fixup, absorb, squash and split with the branch stack along with it.
- Squash: combining commits selected in the graph.
- Dragging branches and commits: rebase by dragging one commit onto another.
- Inspection: the "Commit overlap" analysis shows which commits touch the same lines, which helps you decide what to combine and what can be reordered.
- Undo and redo.