Skip to content

Staging

Stage a whole file, one hunk, or the exact lines you accept.

A commit does not have to contain everything you changed. stage can put a whole file into the index, or one hunk of it, or the individual lines you select.

An agent writes a change in one pass. The change is rarely all correct or all wrong. You stage the part you accept. The rest stays in the working tree for another pass.

Each granularity has one key:

Granularity Where Keys
Whole file files panel space
One hunk staging editor a, then space
Individual lines staging editor v, then space
  1. Move the cursor to the file in the files panel.
  2. Press space.
The files panel. One key stages the file, and the same key unstages it.

The file moves to the index. The status column shows M. for a file that is staged. It shows MM for a file that is staged and still has more changes.

To unstage the file, press space again.

Press enter on a file to open the staging editor. The editor shows the changes that are not in the index yet.

  1. Move the cursor into the hunk you want.
  2. Press a. This selects the whole hunk.
  3. Press space.
Inside the staging editor, with the first hunk under the cursor.

The hunk moves to the index. The editor removes the hunk from the view, because the view shows the changes that are still unstaged.

  1. Move the cursor to the first line you accept.
  2. Press v. This starts a selection.
  3. Press j or k to extend the selection.
  4. Press space.
A four-line selection inside one hunk. Only those lines move.

Only the selected lines move to the index. The other lines of the hunk stay in the working tree.

Keys Action
j / k Move the cursor one line
] / [ Move to the next hunk or the previous hunk
< / > Move to the top or the bottom
tab Show the staged side
esc Leave the editor

Press tab to see the changes that are already in the index. The staged side uses the same keys. On that side, space removes the line from the index.

Press d to discard the selection. This command deletes the change from the working tree, so stage asks you to confirm it first.

CAUTION: Do not discard lines that you did not read. z cannot undo a discard, because the change was never in git.

stage builds a patch for the lines you selected. Then it runs git apply --cached with that patch. There is no second implementation of the index, and there is no git library. The real git binary does the work.

To read the exact command, press @. This opens the command log.