Staging patches with Git add -p

The tiny Git trick sparking big feelings, power-user flexes, and line-by-line envy

TLDR: The article says a built-in Git feature lets you save only selected parts of your work, helping keep changes neat and easier to review. Commenters agreed that’s useful, but instantly split into camps: command-line purists, editor fans bragging their tools already do it better, and annoyed users wanting finer control.

A humble coding tip about carefully choosing what parts of a file get saved somehow turned into a full-blown comment-section talent show. The article’s basic pitch is simple: instead of tossing every change into one messy save point, you can use git add -p to pick pieces one by one. It’s like packing for a trip and deciding exactly what makes it into the suitcase. Sensible! Helpful! And apparently enough to unleash a wave of “welcome to the future” reactions from developers who have been doing this for years.

The strongest vibe in the comments? Power-user peacocking. One commenter dropped a custom script using grepdiff like they were unveiling a secret martial art, while another casually informed everyone that IntelliJ has had shiny visual checkboxes for this since 2018. Translation: half the room was saying, “Yes, this is essential,” and the other half was saying, “Cute, my editor solved this ages ago.” Classic.

But not everyone was impressed. One frustrated voice complained that splitting changes into chunks is still a pain, begging for the ability to split by individual line instead. Others chimed in with practical alternatives, including VS Code’s easier visual tools and a sneaky trick for newly added files. The humor here is deliciously nerdy: the real drama isn’t whether the feature works, but whether doing it in the command line makes you a disciplined craftsperson or just someone voluntarily living in 2009. Either way, the comments agree on one thing: making cleaner save points matters, and everyone has very loud opinions on the “right” way to do it.

Key Points

  • The article explains that `git add -p` allows interactive staging of changes before committing.
  • It states that reviewing diffs during staging can help identify mistakes such as bugs and typos.
  • It describes Git's use of hunks to represent parts of a file that can be staged independently.
  • The example shows a diff in `main.mts` being split so only the `div` function is staged while the `avg` function remains unstaged.
  • The article says `git status` can confirm partial staging because the same file will appear in both staged and unstaged sections.

Hottest takes

"IntelliJ has that since 2018" — deepsun
"I find splitting hunks a pain" — zikohh
"Super useful, and easy to do in the VS Code merge pane" — prideout
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.