Skip to content
Versora

Manual

Worktrees

Move changes and commits between worktrees

7 min read

On this page

Sometimes you start a fix in the wrong folder, or realize a commit belongs to another worktree's branch. Instead of stashing, switching tabs and applying the stash, Versora moves the changes or the commits straight from one folder to the other. First it checks whether anything would conflict in the target. Afterwards, the success notice has Undo, which reverts both sides at once.

This page has two features:

  • Move uncommitted changes;
  • Cherry-pick or move commits to another worktree.

Move uncommitted changes

Takes changed files (staged or unstaged) from one worktree to another of the same repository. The files leave the source and arrive in the target unstaged. With the copy option, they also stay in the source.

Where to find it

  • A worktree's menu (the WORKTREES section or its WIP row in the graph):
    • Bring the changes over here…: from that worktree to the current tab;
    • Send the changes from here to there…: from the current tab to that worktree.
  • The same two buttons in the right panel, with another worktree's WIP row selected.
  • The menu of the tab's own WIP row (the top of the graph): Move the changes to worktree › ‹folder› (‹branch›).
  • A file's menu in the changes panel: Move to worktree › ‹folder› (‹branch›). It takes only that file. It doesn't show up for conflicted files or for a commit's files.
  • Palette (Ctrl+P): "Move the changes to worktree ‹folder›…" (detail: "Branch ‹branch›"). One command shows up per worktree, for the first eight, when the current tab has changes.

Step by step

  1. Choose one of the entries above. The Move changes to another worktree window shows "Checking the changes…".
  2. Read the header: "From ‹source› to ‹target›." and one of these sentences:
    • "Both worktrees are on the same commit: the files go as they are.";
    • "The worktrees are on different commits (‹sha› and ‹sha›): the changes are combined with the target's commit, like a merge."
  3. Under Changed files, leave checked the files that go. A file that can't go comes unchecked, with the reason.
  4. Wait for "Checking whether the changes apply cleanly in the target…". When everything is fine, the window says "N files apply cleanly in the target. They arrive unstaged."
  5. If you want to keep the changes in the source too, check Copy instead of moving (the changes also stay in ‹source›).
  6. Click Move N files (or Copy N files).
  7. The notice "N files moved to ‹target›." comes with the Undo button.
OptionWhat it doesDefault
Changed filesChooses which files go.All the ones that can go
Copy instead of movingThe changes arrive in the target and stay in the source.Unchecked (moves)

What Versora does in git

  1. The chosen changes become a temporary commit, which doesn't go into any branch.

  2. That commit is combined in memory with the target's HEAD (git merge-tree, without touching any folder). If any file would conflict, nothing is moved.

  3. In the target, the files get the result:

    bash
    git restore --source=<combined tree> --worktree -- <files>
    git add -N -- <new files>   # "intent-to-add", so undo can take them out
    
  4. In the source (if it isn't a copy), the tracked files go back to HEAD and the new ones leave the disk:

    bash
    git restore --source=HEAD --staged --worktree -- <tracked files>
    

    Folders left empty are removed too.

How to undo

  • The success notice has Undo, which reverts both sides at once, in the right order ("Undone in both worktrees.").
  • Or use Ctrl+Z in each tab: in the target's tab, it undoes the arrival ("Changes from ‹source›"); in the source's tab, it brings the changes back ("Changes sent to ‹target›"). Before moving, the app keeps a copy of the files on both sides.
  • "Another operation happened since: use Ctrl+Z in each worktree's tab.": the notice's Undo only works while nothing else has changed on either side. After that, undo tab by tab.

Caveats and messages

  • "There are no uncommitted changes to move.": the source is clean.
  • Reasons a file can't go: "conflicted", "it's a submodule" and "the target also has changes in this file".
  • "N files would conflict in the target (‹files›): uncheck them or commit there first.": combining them with the target's commit would conflict in those files.
  • "The two folders are on different commits: combining the changes needs git 2.40 or newer.": with the worktrees on different commits, combining uses a git 2.40 feature. Update git or bring both worktrees to the same commit.
  • "The target worktree has a ‹operation› in progress." and "This worktree has a ‹operation› in progress: finish or abort it before moving changes.": finish the stopped rebase, merge, cherry-pick or revert first.
  • "One of the folders has no commits yet.": one of the sides is a repository with no commits.
  • "The changes reached the target, but couldn't be taken out of the source: ‹error›": the target has already received the files; check the source and discard them there, if needed.
  • "The two folders aren't worktrees of the same repository." and "The source and the target are the same folder.": choose another target.

Cherry-pick or move commits to another worktree

Applies one or more commits to the branch checked out in another worktree. There are two variants:

  • Cherry-pick into another worktree: the commits are applied there and stay here;
  • Move to another worktree: the commits are applied there and then leave the branch here. It only works for the commits at the top of the current branch, in sequence and with no merges.

Where to find it

  • A commit's menu in the graph: Cherry-pick into another worktree › ‹folder› (‹branch›) and Move to another worktree › ‹folder› (‹branch›). "Move" is disabled when the commit isn't the one at the top of the current branch.
  • The menu of a selection of several commits (Ctrl+click or Shift+click in the graph): the same two submenus, for all the chosen commits.
  • The items don't show up for merge commits or stashes, or when the repository has no other worktree.

Step by step

  1. Right-click the commit (or the selection) and choose the target worktree in one of the two submenus.
  2. The confirmation window shows the target, the list of commits in the order they'll be applied and, with git 2.40 or newer, the preview:
    • "Preview: applies without conflicts."; or
    • "Preview: the commit ‹sha› will stop with conflicts in N files (‹files›). You resolve them in the other worktree's tab."
  3. Click Cherry-pick, Move or, with a conflict expected, Cherry-pick anyway.
  4. If the cherry-pick stops at a conflict, the notice "The cherry-pick stopped with a conflict in the worktree ‹target›. Open its tab to resolve it (Continue or Abort)." comes with the Open worktree button. Resolve it there, in the conflict editor.
  5. Without a conflict, the notice "Cherry-picked N commits into ‹target›." (or "N commits moved to ‹target›.") comes with Undo.

What Versora does in git

In the target worktree's folder:

bash
git cherry-pick <sha1> <sha2> …

For Move, after the cherry-pick goes in without a conflict, in the source folder:

bash
git reset --keep HEAD~<N>

--keep removes the commits from the top of the branch without discarding anything in the working folder.

How to undo

  • Cherry-pick: Ctrl+Z in the target's tab undoes the cherry-pick; the success notice also has Undo.
  • Move: the notice's Undo reverts both sides. From the keyboard, use Ctrl+Z first in the source's tab (the commits come back to the branch) and then in the target's tab (the cherry-pick goes away).
  • A cherry-pick that stopped at a conflict is settled in the target's tab: Abort puts everything back as it was. If you resolve it and click Continue until the end, with the target's tab open in Versora, the whole cherry-pick goes into that tab's Ctrl+Z when it finishes ("Undo: Cherry-pick 2 commits from another worktree"). While it's stopped, Ctrl+Z doesn't undo it.

Caveats and messages

  • "The target worktree has N files with uncommitted changes: commit or stash first.": the cherry-pick needs a clean target.
  • "This worktree has N files with uncommitted changes: commit or stash before moving commits (undo needs a clean folder).": applies only to Move.
  • "Only the commits at the top of the current branch (in sequence, no merges) can be moved. For the others, cherry-pick into another worktree."
  • "Moving requires the commits to apply without conflicts (they only leave here after arriving there). Cherry-pick and resolve the conflict first.": with a conflict expected, only the cherry-pick is offered.
  • "This worktree is in detached HEAD: there's no branch to take the commits from."
  • "The target worktree changed since it was checked (another commit or another branch): no commits were applied. Check again before copying or moving the commits.": the target moved to another commit or branch between the window and the run. Open the window again.
  • "This worktree changed since it was checked (another commit or another branch): the commits weren't taken out of it. If they had already reached the other worktree, they're still there; check both branches before going on.": with Move, the commits had already been applied in the target, but the source changed before they left it.

Caution

If the moved commits were already on the server, the source branch ends up behind the remote. Pushing it will need a force push. Preferably move commits that haven't been pushed yet.

There's no setting of its own. The conflict check uses the same preview as the regular cherry-pick (git 2.40 or newer), described in Cherry-pick.

See also