'What's the point of "edit" option in `git reset --patch"

What is the use case of git reset -p and then using "e" option to edit an applied hunk before resetting it ?

I tried playing around with the command but all edits I tried were refused by git.



Solution 1:[1]

The other answer and comments discuss git add, but the question is about git reset. When using reset, you are editing the patch that will be "backed out" of the current index (i.e. what is already staged), so you can't just edit the patch to be what you wish you'd originally staged.

- lines will be added relative to the current index, and + lines will be deleted from the current index.

Solution 2:[2]

I think the man page explains the use case, and also the common pitfalls you have encountered (edited for formatting):

-e, --edit
       Open the diff vs. the index in an editor and let the user edit it.
       After the editor was closed, adjust the hunk headers and apply the patch
       to the index.

       The intent of this option is to pick and choose lines of the patch to
       apply, or even to modify the contents of lines to be staged. This can be
       quicker and more flexible than using the interactive hunk selector.
       However, it is easy to confuse oneself and create a patch that does not
       apply to the index. See EDITING PATCHES below.

I've seen people use this command effectively; it's great for deleting extra lines and whitespace, logger and debugger statements, or fixing last-minute typos. But it should be used sparingly because it's easy to create a patch that does not apply.

When that happens, you can discard the change with n and make the correct change in your text editor.

See man git-add for more info.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 vertere
Solution 2