git hunk edit mode - how to remove a '-' line?

GitPatch

Git Problem Overview


+ bbb
- aaa

# ---
# To remove '-' lines, make them ' ' lines (context).
# To remove '+' lines, delete them.
# Lines starting with # will be removed.
#
# If the patch applies cleanly, the edited hunk will immediately be
# marked for staging. If it does not apply cleanly, you will be given
# an opportunity to edit again. If all lines of the hunk are removed,
# then the edit is aborted and the hunk is left unchanged.

I simply don't understand what make them ' ' lines means. How to apply + bbb only but not - aaa?

Git Solutions


Solution 1 - Git

make them ' ' lines means you need to replace the - in front of the line with a (space).

Solution 2 - Git

A hunk like this:

+ bbb <-- line added
- aaa <-- line deleted
  ccc <-- line unchanged

will turn into content like this:

bbb
ccc

To keep a line marked for deletion (prefixed with '-'), turn it into a line with the same prefix as the unchanged line above (so it will stay the same):

+ bbb
  aaa
  ccc

When the hunk is applied, the contents will look like this:

bbb
aaa
ccc

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLai Yu-HsuanView Question on Stackoverflow
Solution 1 - GitdmedvinskyView Answer on Stackoverflow
Solution 2 - GitellothethView Answer on Stackoverflow