Hacker News new | ask | show | jobs
by ckuehl 3939 days ago
You can simply use `git add -p` to stage hunks individually (or `git reset -p` to unstage some hunks).
2 comments

"git add -p" can be fun, but it's a little scary because it's super easy to end up making commits that don't actually stand on their own. Super simple to miss an import here or a new field there. If you do a whole series of them, it might actually be worse for others to come back to (or bisect in) if they don't realize the original developer never actually compiled and tested each commit as-is.
Well ideally you could use `git stash -k -u` (-keep index, stash -untracked) to set your working directory to the state you're actually committing, and then run some tests.

For the most part though, I just try to avoid having so many hunks to step through that this is even an issue.

And `git checkout -p` to erase hunks from the working directory. (i.e. delete without saving!)
That's a little dangerous! I use git stash -p instead, and only drop it after I'm absolutely sure.