thiagowfx's avatar

Β¬ just serendipity πŸ€ (not just serendipity)

hunk: review diffs in the terminal

β€’ 329 words β€’ 2 min β€’ updated

Previously.

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:

shell
% brew install hunk
% hunk --version
0.25.0

From a Git repository, open the working tree diff:

shell
% hunk diff

Unlike plain git diff, this includes untracked files. To exclude them:

shell
% hunk diff --exclude-untracked

The 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:

shell
% hunk diff --staged
% hunk show HEAD
% hunk diff HEAD~1 HEAD

Limit the review to a file. Here is the draft of this post:

shell
% hunk diff -- content/posts/2026-11-28-hunk-review-diffs-in-the-terminal.md

To use Hunk as the Git pager:

shell
% git config --global core.pager 'hunk pager'
% git diff
% git show HEAD

Git 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:

shell
% hunk diff --watch

Useful when a coding agent is editing the same working tree. Leave Hunk open in another terminal and review the changes as they arrive. ∎

πŸ€– This post was drafted with an AI agent through /bloggify, then reviewed and edited by me. More agent-assisted posts.

ESC