Skip to content
Versora

Manual

Stacks

Changing the stack structure

9 min read

On this page

A stack rarely comes out right the first time. Sometimes one part should come before another, two branches that are too small should be one, or a branch that's too big should become two. Versora makes these changes with a plan beforehand and a single operation, which Ctrl+Z undoes entirely, recorded parents included.

All the operations that rewrite commits (move and fold) use the same mechanism as the restack: a single git rebase -i, which only writes the refs at the end. A conflict stops in the conflict editor, Continue goes on and Abort leaves everything as it was, parents included. The split doesn't rewrite anything.

Moving up or down in the stack

Swaps a branch with its neighbor. The commits are rebuilt in the new order.

Example: main ← feature/a ← feature/b. Move down on feature/b leaves main ← feature/b ← feature/a: the commits of feature/b now go first onto main, and those of feature/a go on top of them.

Where to find it

  • Branch menu › Branch stack › Move up in the stack or Move down in the stack.
  • Palette (Ctrl+P): "Stack: move the branch up" and "Stack: move the branch down" (detail: "Swaps feature/b with its neighbor and rebuilds the commits in the new order").
  • STACKS section: drag the branch row (see below).

Move up only works when the branch has exactly one branch on top. Move down only works when the one below is a stack branch with a single branch on top. In the other cases the item is disabled, and the palette says why: "The branch doesn't have exactly one branch on top." or "The branch below isn't a stack branch with a single branch on top.".

Dragging in the STACKS section

  1. Click and hold a row in the STACKS section (outside the buttons).
  2. Drag it over another row of the same stack. A mark shows where the branch will go: dropping on the upper half of a row puts the branch before it (lower in the stack), on the lower half, after it.
  3. Drop it. The same reorder plan opens.

You can only reorder a straight part of the stack. Otherwise you see "feature/b and feature/x aren't on the same line of the stack: only a straight part can be reordered.".

The plan

The Reorder the stack feature/a? dialog shows:

  • "2 branches are rebuilt, bottom to top:" and one line per branch, with how many commits go onto which parent;
  • "Parents that change:" with "• feature/b: feature/a → main" for each change;
  • "Already on the server and changing: … Afterwards, "Push the stack" force pushes them (with --force-with-lease).";
  • "New order, bottom to top: feature/b → feature/a.";
  • where you end up and the safety note.

If a branch that changes parent has a merge request, the Retarget on the server the merge requests of the branches whose parent changes (!11 → main, …) option appears, checked.

Click Reorder. The bar shows "Reordering the stack…"; at the end, "Stack reordered: 2 branches rebuilt.", with Push the stack when any of them was already on the server.

How to undo

Ctrl+Z undoes "Reorder stack (feature/b ↔ feature/a)": the branches and the parents go back to what they were. The retargeting on the server doesn't come back.

Fold into the branch below

Combines a branch with the branch below it: the commits of both end up in a single branch, and the other one leaves the stack. Use it when two branches are too small to review separately.

Where to find it

  • Branch menu › Branch stack › Fold into feature/a…
  • Palette: "Stack: fold the branch into the one below" (detail: "The commits of feature/b move into feature/a").

The lowest branch of the stack has no stack branch below it: the item is disabled, and the palette says "The branch is the bottom of the stack.".

Step by step

  1. On feature/b, choose Fold into feature/a…
  2. In the Fold feature/b into feature/a? dialog, choose in Name to keep:
    • feature/a (the lower one, default): "The commits of feature/b move into feature/a, and the branches on top of feature/b now sit on top of feature/a.";
    • feature/b (the upper one: the lower commits move into it): "feature/b keeps its commits and those of feature/a; feature/a goes away and the branches on top of it move onto feature/b." Changing the choice redoes the plan, and the dialog shows the new plan before doing anything.
  3. Check the plan: what each branch takes, the parents that change, "feature/b leaves the stack and the local branch is deleted at the end (Ctrl+Z brings it back)." and the branches that will need a force push.
  4. Adjust the options and click Fold.
  5. At the end: "feature/b was folded into feature/a. Push the stack so the server gets the change.", with the Push the stack button.
OptionWhat it doesDefault
Name to keepWhich of the two names stays.the lower one
Retarget on the server the merge requests of the branches whose parent changes (…)Changes the target of the upper merge requests through the API, reading the target again first.checked
Close !11 of feature/b, with a comment explaining whyCloses the merge request of the branch that leaves, with the comment "The commits of this branch were folded into feature/a (by Versora); feature/b left the stack."checked
Also delete the remote branch origin/feature/bDeletes the branch that leaves on the server.unchecked

If you don't close it, the merge request stays open on the server: the plan warns "!11 is the merge request of feature/b: unless you close it, it stays open on the server.".

What Versora does

  1. Rebuilds the branches in the stack's single rebase and records the new parents.
  2. At the end, deletes the local branch that leaves (git branch -D), if it didn't get commits in the meantime.
  3. Then: retargets the upper merge requests, closes the merge request of the one that left and deletes the remote branch, in that order and according to the options. On GitHub, deleting the target of an open pull request closes it; that's why the upper ones are retargeted first.

How to undo

Ctrl+Z undoes "Fold feature/b into feature/a": the deleted branch comes back and so do the parents. The closed merge request, the comment and the deleted remote branch don't come back.

Cuts a branch into two or more stacked branches. The lower commits go to new branches, under the original branch, and the upper ones stay on the branch. Nothing is rewritten: the new branches point to commits that already exist.

Example: feature/b has 5 commits. A cut after the second one creates feature/b-1 with the first 2, and feature/b now sits on top of it with the other 3: main ← feature/b-1 ← feature/b.

Where to find it

  • Branch menu › Branch stack › Split feature/b…. The item also appears on branches outside a stack: the split creates one.
  • Palette: "Stack: split the branch" (detail: "Choose where to cut feature/b into two or more stacked branches").

Step by step

  1. Open Split feature/b. The dialog says: "Choose where to cut: each cut creates a new branch with the commits below it, stacked under the branch. The commits above stay on the branch."
  2. The list shows the branch's own commits, bottom to top, starting from the base: "feature/a (1a2b3c4): where the branch's commits start".
  3. Click ✂ Cut here on the commit where a new branch should end ("A new branch ends at …"). The last commit can't be a cut.
  4. In New branch, check the suggested name (feature/b-1, feature/b-2…) or type another one. Each commit shows which branch it ends up on after the split.
  5. Repeat for more cuts. Remove cut joins the two parts again.
  6. Check "Result, bottom to top: feature/a ← feature/b-1 ← feature/b".
  7. If the branch has a merge request, leave the push and retarget option checked (table below).
  8. Click Split (or Split into 3 branches, with more cuts).
  9. At the end: "feature/b was split; new branches: feature/b-1."
OptionWhat it doesDefault
New branch (at each cut)Name of the branch that ends at that commit.feature/b-N
Afterwards, push the new branches and retarget !11 to feature/b-1 (the merge request then shows only the upper commits)Pushes the new branches and changes the target of the branch's merge request to the last new branch. It only appears when the branch has a merge request.checked

What Versora does in git

bash
git branch --no-track feature/b-1 <cut commit>
git config branch.feature/b-1.versora-parent feature/a
git config branch.feature/b.versora-parent feature/b-1

With the push option, it pushes the new branches in the stack push, with an upstream, and retargets the merge request.

How to undo

Ctrl+Z undoes "Split feature/b": the new branches are deleted and the parents come back. The push and the retargeting on the server don't come back.

Viewing the changes of the branch or the whole stack

Opens, in the central area, the usual file list and diff for:

  • the branch: only its commits, since its base on the parent. It's what its merge request shows;
  • the whole stack: all the branches, from the main branch to the top of the chain, as a single diff.

Where to find it

  • Branch menu › Branch stack › View the branch's changes (since feature/a) or View the whole stack's changes.
  • Stack header in the STACKS section: right-click › View the whole stack's changes.
  • Palette: "Stack: view the branch's changes" (detail: "feature/b since feature/a, as a single diff") and "Stack: view the whole stack's changes" (detail: "Every branch since the main branch, as a single diff").

How to use it

  • The title says what's being compared: "Changes in feature/b since feature/a" or "Changes in the whole stack, from main to feature/c".
  • The summary shows "1a2b3c4 → 5d6e7f8 · 4 files changed · commits: 6".
  • What to compare switches between Branch ("Only this branch's commits, against its parent") and Whole stack ("Every branch of the stack, since the main branch, as a single diff").
  • Click a file in the Changed files list to see its diff.
  • Reload computes it again; Close (Esc) goes back to the graph.

In a tree-shaped stack (a branch with two on top), the whole stack follows the first upper branch.

Caveats and messages

  • "A merge, rebase or cherry-pick is stopped halfway: finish or abort it before changing the stack.": finish the stopped operation first.
  • "There are uncommitted changes and the operation needs to switch branches: commit or stash them first."
  • "feature/b is already the top of the stack." / "feature/a is already the bottom of the stack.": there's nowhere to move it.
  • "feature/a has more than one branch on top: choose the order by dragging the branches in the STACKS section."
  • "That's already the current order.": the drag didn't change anything.
  • "feature/b has fewer than two commits of its own: there's nowhere to cut."
  • "Give the new branch a name.", "Invalid branch name (no spaces, can't start with -).", "A branch named feature/b-1 already exists." and "feature/b-1 is repeated.": fix the cut's name.
  • "feature/b is the main branch: it can't be split into a stack."
  • "Couldn't retarget !11: …" and "Couldn't close !11: …": the local part finished, but the server refused. Do it in the browser.
  • "The operation finished, but the uncommitted changes couldn't be reapplied without a conflict: they're kept in the stash."

There's no preference of its own. Retargeting and closing merge requests need a token that can edit the merge requests. The navigation in the description follows Preferences › Stacks.

See also