tags:

views:

48

answers:

2

I like to use git add --patch (and more recently, git add -i) to untangle my commits as well as verify that what I'm committing is good to go.

Once in a while I'll come across a hunk that might be an error logging statement, an extra newline (usually from erasing the aforementioned logging statement) - something that I'd actually rather remove entirely.

I don't want to stage and I'd also like to simply delete the hunk in question while it's right there in front me of (rather than jumping back to my editor and trying again). I want to apply the change against my working file as well.

Is there a way to do this?


What I've considered is using the edit hunk functionality.

This, in conjunction with the suggestion hash made below gets me a slightly nicer workflow than I have now.

I agree that it's a violation of the git add's separation of concerns. OTOH it would just be so convenient ;P I sound like my boss ;)

A: 

You can add to index whatever you want, commit, then reset hard HEAD, then what was not in the index is lost.

hash
This is not a true solution. The OP mentions untangling commits, and therefore likely has other desirable modifications in the work tree which a reset/stash would kill.
Jefromi
It is what he can do to get what he want, not what he want to be able to do, yes.
hash
+1  A: 

Better than using reset hard HEAD, after committing all your valid hunks, you can just git checkout the file to reset it to what's recorded in the current branch. That way it doesn't affect any other files.

Xentac