80
+ 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?

Lai Yu-Hsuan
  • 27,509
  • 28
  • 97
  • 164

2 Answers2

131

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

ellotheth
  • 4,333
  • 2
  • 17
  • 29
dmedvinsky
  • 8,046
  • 3
  • 31
  • 25
  • 3
    To add to that, if editing with `vim` and you wish to mass-replace across multiple lines, e.g., 7-200, the following command would do: `:7,200s/^-/ /`. This regex searches for a single `-` at the beginning of each line within the specified range and replaces it with a single space. – Adama Jul 11 '17 at 01:17
  • Awesome I have no idea what to do until seen this answer. Thanks – Ryan Chou Mar 10 '18 at 07:10
  • 1
    Note for future self: replace **only** the `-` but keep the rest of the line – Jérôme MEVEL Apr 22 '19 at 08:29
29

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
ellotheth
  • 4,333
  • 2
  • 17
  • 29