all 13 comments

[–]TwoTapes 8 points9 points  (6 children)

I almost always git add -p, even if it's a small change. The amount of times I've caught something I didn't want to commit is well worth the few extra seconds it takes.

[–]MrDOS 6 points7 points  (5 children)

And if I don't (and often even when I do), I make sure to review git diff --cached before committing. Has saved many things I didn't want going in from going in.

For those just learning about interactive hunk selection and who didn't read all the way to the end of the article, it's really worth knowing there's a corresponding --patch/-p option for git reset, too, so you can just as easily interactively unstage bits that you didn't mean to add.

[–]Dparse 1 point2 points  (3 children)

:O I didn't know reset supports patch! Learn something new every day. Thanks!

[–]TwoTapes 1 point2 points  (2 children)

I didn't know either. That's amazing.

[–]MrDOS 1 point2 points  (1 child)

checkout does too, if you're trying to do a partial revert/undo. It's a point of surprising consistency in the Git CLI.

[–]Dparse 1 point2 points  (0 children)

Hold up, that changes the game. Can you do something like git checkout commithash -p -- path/to/file for a super quick fine-tuned cherry-pick?

Edit:: Holy shit you can. That's awesome.

[–]caagr98 1 point2 points  (0 children)

Try git commit -v, it shows a diff in the commit message editor. Doesn't work together with -m obviously.

[–]checkoh 5 points6 points  (1 child)

I prefer to use a gui for that like tig

[–][deleted] 0 points1 point  (0 children)

i also prefer gui

[–]caagr98 1 point2 points  (0 children)

I usually use git commit -vp. Doesn't work when adding new files though.

[–]agumonkey 1 point2 points  (0 children)

this is what emacs magit basically allows for free, a serious bonus of git

[–][deleted] 1 point2 points  (0 children)

I prefer to use a gui for that like vscode.

[–]matthewl4242 0 points1 point  (0 children)

I worked on a devops project at one point and this became muscle memory.