Staging Individual Changes in Sourcetree with Interactive Hunk Selection
Learn how to stage individual diff hunks in Sourcetree’s GUI for fine‑grained commits, with a concrete example, limits, and a fallback to the command line.
06 Feb 2026, 00:48 UTC

The problem: committing only part of a file
When a single file contains unrelated edits—say, a bug fix and a refactor—you often want to split them into separate commits. Editing the file to isolate each change is error‑prone and wastes time. The goal is to stage only the desired diff fragment while leaving the rest untouched.
How Sourcetree’s hunk staging works
Sourcetree shows a visual diff for each modified file. A hunk is a contiguous block of changes surrounded by unchanged lines. By hovering over a hunk you reveal a "Stage Hunk" button (usually a plus sign). Clicking it adds that hunk to Git’s index, the staging area, without affecting other hunks in the same file.
Step‑by‑step example
- Open Sourcetree and select your repository.
- In the "File Status" view, click a text file that shows a yellow badge (modified). The diff pane appears below.
- Identify two separate hunks in the diff. Hover over the first hunk; a small plus icon appears on its left.
- Click that icon. The hunk’s background changes to green, indicating it is now staged.
- Leave the second hunk unstaged (its background stays unchanged).
- Click the "Commit" button at the top. In the commit dialog, verify that the "Staged files" list shows the file with a note like "1 hunk staged".
- Write a commit message and press "Commit".
- To confirm, open a terminal (or use Sourcetree’s "Terminal" tab) and run:
You should see only the lines from the first hunk in the diff output.git show HEAD - The second hunk remains as an uncommitted change in the working copy; running
git diffshows it still present.
Trade‑offs and limits
- File type: The feature relies on Git’s textual diff algorithm. Binary files or large generated files (e.g., minified JS) may not display hunks, forcing you to use the command line.
- Performance: Very large files can make the diff pane lag. Enabling Sourcetree’s "Performance mode" (Preferences → General) reduces UI overhead, or you can fall back to
git add -pfor precise control. - External diff tools: If you have configured an external diff or merge tool, Sourcetree disables its internal hunk staging. Ensure the diff view is set to "Built‑in" under Preferences → Diff to regain the feature.
When to fall back to the command line
If the UI feels slow, or you need to stage lines inside a hunk (e.g., only part of a hunk), use Git’s interactive patch mode:
git add -p <path-to-file>
This walks you through each hunk, letting you edit, split, or skip sections. It works in any environment where Git is available and does not depend on Sourcetree’s UI performance.
Actionable closing
Next time you face a file with mixed changes, try the visual hunk staging approach:
- Open the file’s diff in Sourcetree.
- Stage the hunks you want with the plus button.
- Commit and verify with
git show HEAD. - If the UI lags or the file is binary, switch to
git add -p.
This keeps your commit history clean and your workflow safely within the GUI.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.