git hunk编辑模式 - 如何删除' - '行?

Lai*_*uan 56 git patch

+ 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.
Run Code Online (Sandbox Code Playgroud)

我根本不明白是什么make them ' ' lines意思.如何申请+ bbb但不是- aaa

dme*_*sky 87

make them ' ' lines意味着你需要-(空格)替换前面的行.

  • 除此之外,如果使用`vim`编辑并且您希望跨多行(例如7-200)进行批量替换,则可以使用以下命令:`:7,200s / ^-/ /`。此正则表达式在指定范围内的每一行的开头搜索单个`-`,并将其替换为单个空格。 (2认同)

ell*_*eth 13

像这样的大块头:

+ bbb <-- line added
- aaa <-- line deleted
  ccc <-- line unchanged
Run Code Online (Sandbox Code Playgroud)

会变成这样的内容:

bbb
ccc
Run Code Online (Sandbox Code Playgroud)

要保留标记为删除的行(前缀为'-'),请将其转换为与上一行具有相同前缀的unchanged行(因此它将保持不变):

+ bbb
  aaa
  ccc
Run Code Online (Sandbox Code Playgroud)

应用hunk时,内容将如下所示:

bbb
aaa
ccc
Run Code Online (Sandbox Code Playgroud)

  • 谢谢!这是我找到的最清楚的解释。 (2认同)