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

To stage, commit, fold or split part of a file rather than all of it, add -p (patch). An interactive picker opens before the command runs. It works with add, commit, fold and split.

The Picker

╭─ 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     ││                                │
╰──────────────────╯╰────────────────────────────────╯
 Toggle: space | Confirm: Enter | Help: ? | Cancel: Esc

Files are on the left, their hunks on the right. Check the hunks you want, then confirm. A binary, deleted or empty file, or a submodule, has no hunks to choose from: it shows as one Whole file entry.

KeyAction
↑/k, ↓/jMove
Tab / Shift+TabSwitch pane
SpaceToggle a hunk, or every hunk of a file or directory
EnterConfirm
q / Esc / Ctrl+CCancel, changing nothing
?Help

Commands

CommandPicks fromResult
git loom add -p [<files>]Local changesSelected hunks staged, the others unstaged
git loom commit -b <branch> -p [<files>]Local changesSelected hunks committed to the branch
git loom fold -p [<files>] <commit>Local changesSelected hunks amended into the commit
git loom fold -p <source> <target>A commitSelected hunks moved into an older commit
git loom fold -p <commit> zzA commitSelected hunks uncommitted
git loom split -p <commit>A commitSelected hunks become the first of two commits

Listing files narrows the picker to them. Hunks you leave out are untouched, except with add -p, where unticking a staged hunk unstages it.

Example: Two Changes in One File

You edited src/auth.rs for two features. Send each hunk to its own branch:

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

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

See also: add · commit · fold · split