4 ms·
I advocate: git add -p for interactive staging. It’ll present each hunk of code with a y/n prompt. This is a good habit to prevent committing any debug code o
by magoon 8y ago
I advocate:
git add -p
for interactive staging. It’ll present each hunk of code with a y/n prompt. This is a good habit to prevent committing any debug code or stray marks.
- acemarke 8y agoThat's one of the reasons why I've always preferred a GUI for most of my day-to-day operations. It's a lot easier to click "Add Hunk", or CTRL-click a couple lines and click "Unstage Lines", then it is to go through the CLI options for dozens of hunks. Similarly, SourceTree's interactive rebase UI is great, and when I briefly played with Tower's latest beta, they made it as simple as drag-and-drop for individual commits. On the flip side, it's a lot easier to do "git add -u" or "git add src/some/folder" for those use cases.
- crtasm 8y ago'tig' is a TUI for git, once you learn the shortcuts it's easy to stage specific lines/hunks.
- shocks 8y agogit checkout -p and git reset -p work too :)
- u801e 8y agoI've gone further with this when staging parts of the diff while viewing the output of git diff in vim. You can visually highlight the part of the diff along with the diff header lines and run :'<,'>!git-apply --cached - git apply is one of the git "plumbing" commands that can be used to apply patches to the working directory or the git index.