2

In magit, I can stage or unstage a single hunk (or even parts of a hunk). So those are operations on the index / staging area.

How can I do the corresponding thing but on my working tree?

For example, say I added a one-off comment to myself in some code while debugging. I'm committing the fix -- but I don't want to commit that comment, and in fact since I've fixed the bug, I want to remove it from my working tree, too.

From the command line, git restore --patch <file> does this.

In magit, X (for reset) does that at the level of an entire file.

I want to connect these two things and get hunk-level behavior for magit's reset. Does this exist?

1 Answer 1

1

“k” to discard hunks or even all changes to a file.

3
  • That's exactly it! The only teeny-tiny thing is that I might want k, when used on a staged hunk, to just unstage it but it discards it entirely and reverts the buffer.
    – Dan Drake
    Mar 3 at 21:41
  • If you want to unstage it, then use u instead. It’s no good trying to have one command that reads the user’s mind and does both.
    – db48x
    Mar 3 at 23:28
  • I'm surprised at how many things in emacs do indeed seem to read my mind. There's the whole "dwim" concept, which...does what I mean. :) But, yes, u does unstage the hunk.
    – Dan Drake
    Mar 4 at 12:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.