Skip to content
Versora

Manual

Changes

Staging by file, hunk and line

14 min read

On this page

The stage (or index) is the list of what will go into the next commit. Staging a change is choosing it for the commit; unstaging is taking it out of there. Neither operation touches the file on disk: the change stays in your working directory, it only changes section in the panel.

Versora lets you choose at any size: the whole file, all the files of a folder, everything at once, a hunk (a block of changed lines) or just the lines you mark. That way a commit can take only the bug fix, and the formatting change made in the same file is left for another commit.

Which one to use

You want to…Use
Take a whole fileThe + next to the file, the file menu or S.
Take all the files of a folderThe folder's +, in Tree mode.
Take everythingStage all changes or Ctrl+Shift+S.
Take a block of changes from a fileStage hunk, in the diff.
Take only a few linesThe + that appears on the line, or mark the lines and use Stage lines.
Take out of the stageThe same ways, with unstage (or U and Ctrl+Shift+U).

Tip

Stage and unstage aren't part of Ctrl+Z, because they don't destroy anything: to go back, do the reverse operation. What goes into undo are the discards (see Discarding changes). The exception is staging a conflicted file: it marks the conflict as resolved, so it goes into undo, and Ctrl+Z puts the file back in conflict.

Stage and unstage a file

Takes the whole file to the stage (with all its changes: content, deletion, new file) or takes the whole file out of there.

Where to find it

  • In the changes panel: the + button on the file's row, in Unstaged files (tooltip "Stage file"), and the − button in Staged files (tooltip "Unstage file").
  • File menu: Stage file (in Unstaged files) and Unstage file (in Staged files).
  • In the diff header: the Stage file button ("unstaged" or "new file" diff) or Unstage file ("staged" diff).
  • Shortcut: S stages and U unstages the selected file (see "Staging shortcuts" below).

Step by step

  1. Select the // WIP row in the graph.
  2. In Unstaged files, hover over the src/login.ts file and click the +.
  3. While git works, the toolbar shows "Staging…". The file moves to Staged files.
  4. To unstage it, click the file's − in Staged files ("Unstaging…").

From the keyboard: focus the file in the list (or open its diff) and press S. The focus moves to the file that ended up in the same position in the list and, if the diff was open, opens its diff. That way you review and stage file by file without taking your hands off the keyboard.

What Versora does in git

bash
# Stage (includes deletions and new files)
git --literal-pathspecs add -A -- src/login.ts

# Unstage (on a renamed file, the app passes the old and the new path)
git --literal-pathspecs reset -q HEAD -- src/login.ts

# Unstage in a repository that doesn't have any commit yet
git --literal-pathspecs rm -r -q --cached -- src/login.ts

The paths are passed to git literally (--literal-pathspecs): a file with * or ? in the name doesn't become a wildcard. In practice the app hands the list of paths to git through standard input, which doesn't change the result.

How to undo

Ctrl+Z doesn't undo stage or unstage. Do the reverse: unstage what was staged by mistake, or stage it again. The file on disk never changes in these operations.

The exception is staging a file in the Conflicted section (the + "Mark as resolved (stage)", the menu item with the same name or S). It goes into undo as "Stage of 1 conflicted file", and Ctrl+Z puts the file back in conflict, as it was in the index and on disk.

Caveats and messages

  • Conflicted file: S, the + ("Mark as resolved (stage)") and the menu item with the same name stage the file in the Conflicted section, which marks it as resolved. If the file still has conflict markers (<<<<<<<), all three first ask for the same confirmation as Stage all changes (see "Stage all and unstage all" below). To really resolve it, use the conflict editor.
  • "Wait for the current operation to finish.": another operation of the app is still running.
  • The commit only takes what's in Staged files. If you edit the file again after staging it, the new edit appears in Unstaged files and is left out until you stage it again.
  • If the file is on the "don't commit" list, staging it by hand works, but the commit asks for confirmation. See "Don't commit" list.
  • The S and U keys can be changed in Preferences › Keyboard shortcuts (Keyboard shortcuts).

See also

Stage a whole folder

In Tree mode, each folder has its own button: it stages (or unstages) at once all the files of that folder that are in the section.

Where to find it

  • Changes panel › Tree › hover over a folder:
    • in Unstaged files, + "Stage 4 files in this folder" (or "Stage 1 file in this folder");
    • in Staged files, − "Unstage 4 files in this folder".

Step by step

  1. On the bar below the panel title, click Tree.
  2. Hover over the src/app folder in Unstaged files.
  3. Click the +. All the files of that folder (including those in subfolders) that were unstaged go to Staged files.

What Versora does in git

The same command as staging a file, with the list of all the files of the folder in the section:

bash
git --literal-pathspecs add -A -- src/app/login.ts src/app/logout.ts src/app/menu/item.ts src/app/menu/lista.ts

How to undo

As with a file: Ctrl+Z doesn't undo it; use the − of the same folder in Staged files.

See also

Stage all and unstage all

Takes all the repository's changes to the stage (edited, new and deleted files), or takes everything out of the stage at once.

Where to find it

  • Changes panel: the Stage all changes button on the Unstaged files title and the Unstage all changes button on the Staged files title.
  • // WIP row menu in the graph: Stage all changes.
  • Palette (Ctrl+P): "Stage all changes" and "Unstage all changes". When there's nothing to do, the palette shows the command as unavailable: "there are no files to stage" or "there are no staged files".
  • Shortcuts: Ctrl+Shift+S (stage all) and Ctrl+Shift+U (unstage all).

Step by step

  1. Check the Unstaged files section: everything in it will go in.
  2. Click Stage all changes (or press Ctrl+Shift+S).
  3. The files move to Staged files.

What Versora does in git

bash
# Stage all (the whole repository, not just the current folder)
git add -A

# Unstage all: only the stage goes back to HEAD
git reset -q HEAD -- :/

# Unstage all in a repository that doesn't have commits yet
git rm -r -q --cached .

Unstage all uses the :/ path (the repository root) on purpose: a git reset without a path would also erase the record of a merge in progress, and the next commit would come out with a single parent. With the path, the merge stays in progress.

How to undo

Ctrl+Z doesn't undo it. After staging everything by mistake, use Unstage all changes (and vice versa); the files on disk don't change.

With files in the Conflicted section, staging everything also marks them as resolved and, for that reason, goes into undo ("Stage of 2 conflicted files"). Ctrl+Z returns the files to their state before the stage, with the conflicts back in the index.

Caveats and messages

  • Conflicted files still with markers. Versora checks the files in the Conflicted section before the stage. If any of them still has <<<<<<< inside, it asks first:

    • Title: "Files still have conflict markers".
    • Message: "src/login.ts still has conflict markers (<<<<<<<). Staging marks the conflict as resolved with the markers inside the file. Stage all changes anyway?" (with several files, the list comes in the message).
    • Stage anyway goes ahead; closing the window cancels.

    The same confirmation applies on every path: the Stage all changes button, the // WIP row menu, the palette, Ctrl+Shift+S, Ctrl+Shift+Enter and, for a single file, S, the + and Mark as resolved (stage).

  • Only conflicted files: the Stage all changes button and Ctrl+Shift+S also work when the Unstaged files section is empty and there are only conflicted files.

  • "Unstage all changes" doesn't end a merge in progress. It only empties the stage; the merge keeps waiting for the commit (or for Abort). See Operation in progress.

  • "Don't commit" list. The files on the list are left out of staging everything (button, shortcut, palette and Ctrl+Shift+Enter). During the operation, "Staging (except the "don't commit" list)…" appears and, at the end, a notice such as "2 files weren't staged ("don't commit" list): …", with the Stage them too button. See "Don't commit" list.

  • Line endings: when committing, the app may warn that a file goes with CRLF; see Checks.

  • The shortcuts can be changed in Preferences › Keyboard shortcuts.

See also

Stage and unstage a hunk

A hunk is a block of changed lines, with a few unchanged lines around it (the context). A file's diff shows each hunk with a header like @@ -10,7 +10,9 @@, and each header has its own buttons.

Where to find it

  • "Unstaged" diff, on each hunk's header: Stash, Discard hunk and Stage hunk.
  • "Staged" diff, on each hunk's header: Unstage hunk.

The buttons only appear in the Diff view (only the hunks). In the File view (the whole file), the file becomes a single hunk; there, choose the lines (next section).

Step by step

  1. In the changes panel, click the file in Unstaged files.
  2. On the diff bar, check that Diff is selected (and not File).
  3. Find the hunk that goes into the commit and click Stage hunk ("Staging hunk…").
  4. The hunk disappears from the "unstaged" diff. The file now also appears in Staged files; in the diff's Unstaged | Staged picker, Staged shows what has already gone.
  5. To unstage a hunk, open the "staged" diff and click Unstage hunk.
OptionWhat it doesDefault
Context lines ("− 3 +" on the diff bar)Less context splits nearby changes into smaller hunks, which you stage one by one; more context joins neighboring changes into a single hunk. See Reading the diff.3 (git's default)

What Versora does in git

The app builds a patch with the file header and only that hunk, and hands it to git apply on the stage:

bash
# Stage the hunk
git apply --whitespace=nowarn --cached hunk.patch

# Unstage the hunk (the same patch, reversed)
git apply --whitespace=nowarn --cached --reverse hunk.patch

In the app the patch goes through standard input (-); hunk.patch above is just for illustration. The file on disk doesn't change.

How to undo

Ctrl+Z doesn't undo it. Use Unstage hunk in the "staged" diff (or Stage hunk again).

Caveats and messages

  • With "Ignore whitespace" on, the hunk buttons are disabled, with the tooltip "Unavailable while "Ignore whitespace" is on: the diff without the whitespace doesn't match the real file and can't be safely applied back.". Turn off Ignore whitespace on the diff bar.
  • New (untracked) file: the "new file" diff has no buttons on the hunks; you can only stage the whole file.
  • Binary file or image: only the whole file.
  • Legacy encodings: in a file in Windows-1252, Latin-1 or UTF-16, staging by hunk writes the bytes in the file's own encoding. If the diff was read with the wrong encoding, "The diff was read as UTF-8, but the file has bytes that aren't valid UTF-8. Choose the file's correct encoding before staging or discarding by line or by hunk." appears. See Legacy encodings.
  • If the file changed on disk between reading the diff and the click, git may refuse the hunk (the message comes from git itself). The diff usually refreshes on its own; if not, press F5 and try again.

See also

Stage and unstage lines

When a hunk mixes what goes into the commit and what doesn't, choose line by line. You can take a single line, with one click, or mark several and stage them all together.

Where to find it

  • One line: hover over a changed line of the diff. A + button appears in the margin ("Stage this line"); in the "staged" diff, a − ("Unstage this line").
  • Several lines: click the numbers of the changed lines to mark them. Below the diff, the selection bar appears:
    • in the "unstaged" diff: "3 lines selected", Stage lines, Discard lines, Stash lines, Line history and Clear selection;
    • in the "staged" diff: Unstage lines, Line history and Clear selection.

Step by step

  1. Open the file's diff in Unstaged files.
  2. Click the number of the first line that goes into the commit. It becomes marked.
  3. For a range, Shift+click the number of the last line: all the changed lines between the two are marked, even in different hunks. Click a number again to unmark that line.
  4. Click Stage lines ("Staging lines…").
  5. To clear the marking without doing anything, use Clear selection or Esc (with the focus on the diff).

The choice works in both views (File and Diff) and in both modes (Unified and Split). In split mode, the numbers on the left are the removed lines and the ones on the right, the added lines.

What happens to each line

Marked lineOn stageOn unstage
Added (+)Goes into the stage.Leaves the stage (stays on disk).
Removed (−)The removal goes into the stage.The removal leaves the stage (the line comes back to the stage).
Not markedStays as it was in the stage.Stays as it was in the stage.

Only the changed lines (+ and −) can be marked; context lines can't.

What Versora does in git

The app builds a patch with only the marked lines: the added lines you didn't mark leave the patch, and the removed ones you didn't mark become context. Then it applies it on the stage:

bash
# Stage the lines
git apply --whitespace=nowarn --cached lines.patch

# Unstage the lines (patch built in reverse)
git apply --whitespace=nowarn --cached --reverse lines.patch

The file on disk doesn't change.

How to undo

Ctrl+Z doesn't undo it. Mark the same lines in the "staged" diff and use Unstage lines.

Caveats and messages

  • The selection is cleared whenever the diff's content changes (after a stage, an edit on disk or a refresh).
  • With "Ignore whitespace" on, the lines can't be chosen or staged.
  • New (untracked) file: in the "new file" diff the lines can't be chosen; you can only stage the whole file.
  • The same encoding messages as for staging by hunk apply here (see above).
  • Stash lines saves the marked lines in a stash and removes them from the file: see Stash. Line history shows the commits that touched them: see Line history.

See also

Staging shortcuts

The staging shortcuts let you review and prepare a commit without taking your hands off the keyboard.

The shortcuts

ShortcutWhat it doesWhere it works
SStages the selected file.In the changes panel and in the diff.
UUnstages the selected file.In the changes panel and in the diff.
Ctrl+Shift+SStages everything.With a repository open, outside text fields.
Ctrl+Shift+UUnstages everything.With a repository open, outside text fields.
Ctrl+Shift+EnterStages everything and commits.With a repository open; in a text field, only in the commit message.
Ctrl+Shift+MGoes to the commit message.With a repository open, even in a text field.
Ctrl+EnterCommits (in the commit message).In the commit box (The commit box).
EscCloses the diff, or clears the marked lines.In the diff.

"Selected file" is the row that has the focus in the changes list or, without it, the file whose diff is open.

  • None of these shortcuts fires with the focus in a text field (except the ones indicated in the table), in the integrated terminal or with a dialog, a menu or the palette open.
  • S and U only work in the changes panel and in the diff (or with no focus anywhere). On other screens the letter belongs to them: in the interactive rebase, for example, S marks squash.
  • The staging shortcuts don't work on Home, only in a repository tab.
  • After S or U, the focus moves to the file that ended up in the same position and, if the diff was open, its diff opens.

Ctrl+Shift+Enter in detail

  1. If another commit was selected, the changes panel appears again.
  2. Without a message, nothing is done (not even the stage): the cursor goes to the summary and "Write the commit message first (Ctrl+Shift+M takes you there)." appears.
  3. With the message ready, the app stages everything (except the "don't commit" list). If some conflicted file still has markers, the same confirmation as Stage all changes appears first ("Files still have conflict markers"); canceling does neither the stage nor the commit.
  4. Then the app submits the commit form, with the same checks as the commit button. If the commit button can't be used, its text appears as a notice.

How to undo

The stage isn't part of Ctrl+Z (except for conflicted files, see above). A commit made with Ctrl+Shift+Enter is: undo puts the changes back in the stage. See Undo and redo.

  • All these shortcuts can be changed in Preferences › Keyboard shortcuts ("Changes, diff and commit" group), except Esc, which is fixed. See Keyboard shortcuts.
  • The shortcuts help (F1) lists the keys in effect.

See also