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.
Three granularities
Section titled “Three granularities”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 |
Stage a whole file
Section titled “Stage a whole file”- Move the cursor to the file in the files panel.
- Press
space.
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.
Stage one hunk
Section titled “Stage one hunk”Press enter on a file to open the staging editor. The editor shows the changes
that are not in the index yet.
- Move the cursor into the hunk you want.
- Press
a. This selects the whole hunk. - Press
space.
The hunk moves to the index. The editor removes the hunk from the view, because the view shows the changes that are still unstaged.
Stage individual lines
Section titled “Stage individual lines”- Move the cursor to the first line you accept.
- Press
v. This starts a selection. - Press
jorkto extend the selection. - Press
space.
Only the selected lines move to the index. The other lines of the hunk stay in the working tree.
Move in the editor
Section titled “Move in the editor”| 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.
Discard instead of stage
Section titled “Discard instead of stage”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.
What stage runs
Section titled “What stage runs”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.