Mastering Git Add -p for Precise and Organized Commits

Staging patches with Git add -p

Mastering Git Add -p for Precise and Organized Commits

I rely on git add -p daily to review changes interactively, catching bugs and typos before committing. This tool lets me stage specific hunks within a file, allowing me to group related changes into cleaner, more organized commits. By splitting diffs and selectively approving parts of a file, I maintain greater control over my version history and ensure only the intended code reaches the repository.

If you're not already using git add -p to stage your commits then you're missing out.
  1. chriswarbo

    Magit allows selective staging/unstaging, either of hunks, or by selecting lines (AKA Emacs's "region"). I avoid staging from the git commandline, unless I'm just doing whole files.

    PS: Majutsu provides this too (a magit-like tool for jj)

  2. BeetleB

    > If you’re not already using git add -p to stage your commits then you’re missing out.

    After switching to jujutsu, I assure you I don't miss this feature.

    jj takes the opposite approach. It keeps staging things, and you use split whenever you want to separate things out.

    (And yes, it stores the staged changes as revisions, so you can always back out to a previous staged state).

  3. natbennett

    In the case of a newly committed file you can add just the file with

    git add . -N

    And then review the text itself as part of the git add -p workflow

  4. wps

    While I see the utility of partial file commits, I think that it promotes committing untested code. Fossil scm doesn’t have an equivalent feature because of this very issue.

  5. ninkendo

    My biggest problem with `add -p` is correcting any patches I added or rejected by accident. Often times I skip through dozens of things I don’t want to add, then realized that last hunk was something I did need. But I can’t re-visit it, I have to start over and try extra hard to not skip past it again.

    I wish the j and k shortcuts could revisit hunks I’ve already added/rejected, not just ones I haven’t reviewed yet. On a large set of unstaged changes that you mostly don’t want, it really sucks to “lose your place” in the list of hunks.

More from this day

2026-07-29