Every history command in stage is an interactive rebase. stage writes the todo
list and gives it to git through GIT_SEQUENCE_EDITOR. There is no second
implementation of rebase.
Each rebase runs with --autostash, so a dirty working tree does not stop you.
git puts your changes back when the rebase finishes.
One commit at a time
Section titled “One commit at a time”Press 4 for the commits panel. These keys act on the commit under the cursor.
| Key | Action |
|---|---|
r |
Change the message |
s |
Squash into the parent |
f |
Squash into the parent, and keep the parent message |
d |
Delete the commit |
t |
Revert the commit with a new commit |
g |
Reset the branch to the commit |
e |
Stop the rebase here, so you can amend |
ctrl+k / ctrl+j |
Move the commit up or down |
The rebase plan
Section titled “The rebase plan”For more than one change, plan them together. Press i on the oldest commit you
want to touch.
- Press
4, then move the cursor down to an older commit. - Press
i. The plan opens with every commit set topick. - Press
s,f,d,roreto mark the commit under the cursor. - Press
JorKto move a commit. - Press
enter, theny.
The plan is only in memory, and the header says so. Nothing touches the
repository until you press enter and answer the question.
The fixup loop
Section titled “The fixup loop”You read a commit, you find a fault, and you write the correction. The fix belongs in the commit that caused it, not in a new commit at the top.
- Stage the correction.
- Move to the commit that owns the fault.
- Press
F, theny. stage writes afixup!commit for that commit. - Press
S, theny. Everyfixup!commit folds into its target.
F records the fix against a commit. S folds every fixup in.Press ctrl+f to let stage find the commit for you. stage reads the staged
change, and looks for the commit that last touched those lines. It uses the
staged change only, because F and A both consume the index.
Merge commits
Section titled “Merge commits”stage refuses to rewrite a merge commit, and says which command refused:
cannot edit a merge commitcannot squash into a merge commitcannot move a merge commithistory above the target contains a merge commit — not supported yetA flat todo list turns a merge into one ordinary commit, and the second parent is lost. stage stops instead.
When it stops
Section titled “When it stops”A rebase replays commits, and a replay can conflict. Read Conflicts for the keys that continue, skip, or abort.
An edit step also stops the rebase, on purpose. stage says so, and m shows
the options.
Press z to undo, and Z to redo. stage reads the reflog, so a rewritten
commit is still reachable after the rewrite.
CAUTION: Do not rewrite commits that other people already pulled. A rewrite gives every commit after it a new hash.