β’ 329 words β’ 2 min β’ updated
Problem statement: how can we review a changeset in the terminal, one hunk at a time, without staging anything?
Hunk is a terminal diff viewer. It displays the whole changeset in one scrollable view, with a file sidebar and syntax highlighting.
Most Git subcommands we use for code review have corresponding Hunk commands.
For example, git diff, git show, git log, git status, and git stash show
become hunk diff, hunk show, hunk log, hunk status, and hunk stash show.
Install with Homebrew:
% brew install hunk
% hunk --version
0.25.0From a Git repository, open the working tree diff:
% hunk diffUnlike plain git diff, this includes untracked files. To exclude them:
% hunk diff --exclude-untrackedThe keyboard controls we need first:
]/[: next / previous hunk../,: next / previous file.j/k: move down / up.1/2/0: unified / split / automatic layout.?: help.q: quit.
Automatic layout uses split view in wide terminals and unified view in narrow ones. Click a file in the sidebar to jump straight to it.
Review the staging area, the last commit, or a pair of revisions:
% hunk diff --staged
% hunk show HEAD
% hunk diff HEAD~1 HEADLimit the review to a file. Here is the draft of this post:
% hunk diff -- content/posts/2026-11-28-hunk-review-diffs-in-the-terminal.mdTo use Hunk as the Git pager:
% git config --global core.pager 'hunk pager'
% git diff
% git show HEADGit now sends its diff output to Hunk. Unlike hunk diff, this does not
include untracked files. Non-diff output, such as git log, uses a plain-text
pager instead: HUNK_TEXT_PAGER, then PAGER, then less -R on macOS/Linux.
For a review that reloads as files change:
% hunk diff --watchUseful when a coding agent is editing the same working tree. Leave Hunk open in another terminal and review the changes as they arrive. β
/bloggify,
then reviewed and edited by me.
More agent-assisted posts.