Stacks
Restacking
6 min read
When you change a branch in the middle of the stack (a new commit, an amend, a rebase onto the
updated main), the branches above it are still built on the old version. In the STACKS section
they get the restack chip. "Restack" redoes the rebase of each branch onto its parent's new tip,
bottom to top, in a single operation.
Example: you fixed a bug in feature/a with a new commit. After the restack:
feature/bis rebuilt on the new tip offeature/a;- next,
feature/cis rebuilt on the new tip offeature/b.
- STACKS section: restack button in the stack header (tooltip: "Restack (a branch's parent moved)"). It only appears when there's a branch to restack.
- Branch menu › Branch stack › Restack.
- Stack header in the STACKS section: right-click › Restack.
- Palette (Ctrl+P): "Restack" (detail: "Cascading rebase, bottom to top").
- After Stack on…, with the Restack right after (rebase onto the new parent) option checked.
- Open Restack from any branch of the stack.
- Versora builds the plan. If nothing needs to change, you see "feature/a is already up to date: every branch starts at its parent's tip." and nothing happens.
- Check the plan in the Restack feature/a? dialog:
- how many branches get rebased and, for each one, how many of its own commits go onto which parent (a branch with no commits of its own appears as "no commits of its own, just moves onto feature/a");
- where you end up: "You stay on feature/c." or "The rebase runs on feature/c and checks out feature/a again at the end.";
- how many of these branches are already on the remote and will need a force push afterwards;
- the safety note: "A conflict stops in the conflict editor: Continue resumes the cascade and Abort leaves everything as it was. Ctrl+Z undoes the whole restack."
- Click Restack. The bar shows "Restacking…".
- At the end, the notice "Stack updated: 2 branches replayed.". If any of them was already on the remote, the notice has the Push the stack button.
Everything runs in a single git rebase -i, with the todo list built by Versora. For each branch
that needs to change, and for all the ones above it, bottom to top:
reset <parent's new tip>
pick <each of the branch's own commits>
label <this branch's new tip>
update-ref refs/heads/feature/b
It's the same mechanism as git rebase --update-refs (git 2.38 or newer): the branch refs are only
written at the end. The command is similar to:
git rebase -i --autostash --no-autosquash --empty=drop --no-fork-point --onto <tip> <tip> feature/c
- Each branch's own commits come from the recorded base (
branch.<name>.versora-base). That's why the parent's commits aren't replayed, even after an amend on the parent. --empty=drop: a commit that becomes empty (its content is already below, for example after a squash) disappears, instead of stopping to ask for a decision.--autostash: your uncommitted changes go to a stash and come back at the end.- At the end, each branch's base is updated to its parent's new tip.
- When the current branch is part of the stack, the rebase ends on it, and you stay where you were.
Without update-ref in the todo list, each branch's tip goes to a temporary ref
(refs/versora/stack/new/<n>), and a last step moves all the branches at once, checking each one's
old value. The plan warns: "This git doesn't support update-ref in a rebase (it's older than 2.38):
all branches are moved together in a final step." The result is the same.
Preferences › Stacks shows which path applies on this machine.
If a commit doesn't fit onto the parent's new tip, the rebase stops, as in an ordinary rebase:
- You see the notice "The restack stopped on a conflict in feature/b (a1b2c3d). Resolve it in the conflict editor and click Continue to resume the cascade, or Abort to leave everything as it was.". Versora selects the WIP row in the graph.
- The STACKS section shows "Restack stopped at feature/b. Resolve the conflicts and use Continue or Abort in the changes panel."
- Resolve the conflicting files in the conflict editor (see Conflicts).
- Click Continue in the changes panel. The cascade resumes where it stopped, because it's the same rebase.
- When it finishes, you see "The restack finished: 2 branches replayed. Ctrl+Z undoes all of it.".
Abort puts everything back the way it was: no ref was touched until the end. In that case, the notice is "The restack was aborted; the branches are as they were.".
If the rebase stops for another reason (a commit git couldn't apply, a hook), the notice is "The restack stopped at feature/b (a1b2c3d). See git's output in the activity log; Continue resumes the cascade, Abort leaves everything as it was."
Ctrl+Z undoes "Restack feature/a" entirely: all the branches go back to what they were before, at once. This also applies when the restack stopped on a conflict and finished after Continue.
Ctrl+Z doesn't touch the server. If you already pushed the restacked stack, undoing only changes the local branches; a new force push would be needed to bring the server back.
- "A merge is in progress: finish or abort it before updating the stack." (or rebase, cherry-pick, revert): finish or abort the stopped operation first.
- "There are uncommitted changes and you're outside the stack: commit or stash them first.": with the current branch outside the stack, the rebase would have to switch branches.
- "feature/b has merge commits: updating the stack only replays linear history. Rebase it by hand.": a merge inside a stack branch prevents the restack.
- "feature/b is in use in the worktree …: update the stack from there or close that worktree.": the branch is checked out in another worktree.
- "The update would replay 2500 commits (the maximum is 2000). Check the parent of each branch.": a parent is probably wrong. Use Stack on… to fix it.
- "Couldn't find where the commits of feature/b start on top of feature/a.": Versora doesn't know the branch's base. Use Stack on… again.
- "The stack changed after it was checked. Review the plan again.": a branch moved between the plan and the run. Open the restack again.
- "The stack was updated, but your uncommitted changes couldn't be reapplied without a conflict: they're kept in the stash.": apply the stash whenever you want (see Undo and stash).
- "The stack was updated, but checking out feature/a again failed: …": the branches are right; do the checkout by hand.
Caution
After the restack, the branches that were already on the remote have a new history. Their push needs to be forced: use Push the stack, which does that with --force-with-lease.
- Preferences › Stacks › How it works: says whether this machine's git supports
update-refin a rebase ("This machine's git supports update-ref in a rebase (2.38 or newer)." or the fallback path warning). - The restack's autostash is always on and doesn't depend on Preferences › Operations.