Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Selecting Hunks with -p

Sometimes you want to stage or commit only part of your changes — a few specific lines rather than entire files. The -p (patch) flag opens an interactive TUI that lets you pick individual hunks before the operation runs. It works with add, commit, and fold.

The TUI

╭─ Files ──────────╮╭─ Diff ─────────────────────────╮
│ M  main.rs       ││ [✓] Hunk 1/3 (staged)          │
│ ▼ src/           ││ @@ -10,4 +10,6 @@              │
│   MM lib.rs      ││ -old line                      │
│   A  new.rs      ││ +new line                      │
│ ?? README.md     ││                                │
╰──────────────────╯╰────────────────────────────────╯
 Navigate: ↑/↓ or j/k | Switch Pane: tab | Toggle: space | Confirm: c or Enter | Quit: q or Esc

The left pane lists files with git status–style codes (M, MM, A, ??, D). The right pane shows diff hunks — check the ones you want, leave the rest unchecked, then confirm.

KeyAction
/ k, / jNavigate up/down
Tab / Shift+TabSwitch between left and right pane
SpaceToggle hunk (right pane) or all hunks in file/directory (left pane)
c / EnterConfirm selections
q / Esc / Ctrl+CCancel without changes

Staging hunks (add -p)

To stage a subset of changes before any commit:

$ git loom add -p
# Opens TUI showing all changed files

Filter to specific files:

$ git loom add -p src/auth.rs
$ git loom add -p a3          # using a short ID

Committing hunks (commit -p)

Commit only selected hunks to a feature branch, without staging anything first:

$ git loom commit -b feature-auth -p
# Opens TUI for all working tree changes
# Only selected hunks are committed to feature-auth

You can narrow the picker to specific files:

$ git loom commit -b feature-auth -p src/auth.rs -m "partial auth fix"
# TUI shows only src/auth.rs hunks
# Other staged files are saved aside and restored after the commit

Amending hunks into a past commit (fold -p)

Fold only selected working tree hunks into an existing commit:

$ git loom fold -p d0
# Opens TUI for all working tree changes
# Selected hunks are staged and folded into commit d0

Narrow to specific files by listing them before the target:

$ git loom fold -p src/auth.rs d0
# TUI shows only src/auth.rs hunks
# Selected hunks are folded into d0; the rest stay in the working tree

Common patterns

Split a file’s changes across two commits

You edited src/auth.rs and want different hunks in different branches.

$ git loom commit -b feature-auth -p src/auth.rs -m "tighten auth check"
# Pick the first hunk → committed to feature-auth

$ git loom commit -b feature-ui -p src/auth.rs -m "restyle auth form"
# Pick the remaining hunk → committed to feature-ui

Amend only part of a file into a past commit

$ git loom fold -p src/auth.rs d0
# Opens TUI filtered to src/auth.rs
# Pick only the hunks that belong in d0
# Unselected hunks stay in the working tree unchanged

Stage interactively, then commit

If you prefer to separate the two steps:

$ git loom add -p
# Select exactly what to stage

$ git loom commit -b feature-auth -m "fix auth check"
# Commits whatever is staged

See also: add · commit · fold