为什么 git add -p 中缺少拆分选项?

Why is split option missing in git add -p?

试图通过 git add -psplit 选项将大块分割成更小的块,但整个文件显示为一个大块,我无法分割它。

  1. 我可以编辑,但删除行会导致补丁失败。
  2. git help add 说我应该拆分,我记得使用过它,但在我当前的示例中,该选项没有出现在提示中。
  3. 当我选择选项 help 时,它说我可以选择 s 来拆分 :-[

Git 版本:1.9.1。 Xubuntu 14,我的 zsh。 hunk 不是一行,而是多行。知道为什么会这样吗?

编辑了更多数据,这里是控制台日志:

+last line of long text 
Stage this hunk [y,n,q,a,d,/,e,?]? s
y - stage this hunk
n - do not stage this hunk
q - quit; do not stage this hunk nor any of the remaining ones
a - stage this hunk and all later hunks in the file
d - do not stage this hunk nor any of the later hunks in the file
g - select a hunk to go to
/ - search for a hunk matching the given regex
j - leave this hunk undecided, see next undecided hunk
J - leave this hunk undecided, see next hunk
k - leave this hunk undecided, see previous undecided hunk
K - leave this hunk undecided, see previous hunk
s - split the current hunk into smaller hunks
e - manually edit the current hunk
? - print help

它不起作用的原因是因为你的大块头已经小到 git 会自动得到它。只有当有未更改的行将更改的行分隔得足够近以至于 git 认为它们属于一起时,拆分才有效。

为了实现你想要的,你需要manually edit the patch

Why is split option missing in git add -p?

在 Git 2.17(2018 年第 2 季度)中,您不必问这个问题,因为 single-key 现在仅针对已启用的键提供帮助(例如,当只有一个 hunk 时,将不会显示“/”的帮助)。

commit 4bdd6e7, commit 88f6ffc, commit 01a6966 (13 Feb 2018) by Phillip Wood (phillipwood)
(由 Junio C Hamano -- gitster -- in commit 60f8b89 合并,2018 年 3 月 6 日)

第一个:

add -p: improve error messages

If the user presses a key that isn't currently active then explain why it isn't active rather than just listing all the keys. It already did this for some keys, this patch does the same for the those that weren't already handled.

并且:

add -p: only display help for active keys

If the user presses a key that add -p wasn't expecting then it prints a list of key bindings.
Although the prompt only lists the active bindings the help was printed for all bindings.

Fix this by using the list of keys in the prompt to filter the help.
Note that the list of keys was already passed to help_patch_cmd() by the caller so there is no change needed to the call site.