为什么在git add -p中缺少split选项?

LAF*_*ica 23 git git-add

试图通过git add -psplit选项将一个大块分成较小的一个,但是整个文件看起来像一个大块而且我不能拆分它.

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

Git版本:1.9.1.Xubuntu 14,哦-my-zsh.大块头不是一行,而是多行.任何想法为什么会这样?

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

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

Jef*_*ett 27

它不起作用的原因是因为你的大块头已经小了,因为git会自动获得它.拆分仅当有未更改的行分隔更改的行足够接近git假定它们属于一起时才有效.

为了达到你想要的效果,你需要手动编辑补丁

  • 啊哈!实际上,未更改的行分隔了已更改的行.在这种情况下,我只是在没有git的情况下拆分内容并将其添加到部分中./我谢谢! (4认同)

Von*_*onC 5

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

您不必在 Git 2.17(2018 年第二季度)中问这个问题,因为现在仅针对已启用的键提供单键帮助(例如,/当只有一个大块时,不会显示“ ” 的帮助) .

请参阅Phillip Wood ( ) 的提交 4bdd6e7提交 88f6ffc提交 01a6966(2018 年 2 月 13 日(由Junio C Hamano合并-- --60f8b89 提交中,2018 年 3 月 6 日)phillipwood
gitster

第一的:

add -p: 改进错误信息

如果用户按下当前未激活的键,则解释其未激活的原因,而不是仅列出所有键。它已经对某些键执行了此操作,此补丁对尚未处理的那些键执行相同的操作。

和:

add -p: 只显示活动键的帮助

如果用户按下了一个add -p不期望的键,那么它会打印一个键绑定列表。
尽管提示仅列出活动绑定,但已为所有绑定打印帮助。

通过使用提示中的键列表过滤帮助来解决此问题。
请注意,help_patch_cmd()调用方已将密钥列表传递给了调用方,因此无需对调用站点进行更改。

  • 点赞!我会接受原样,因为我相信现在更多的人会从中受益。不过还是谢谢@VonC! (2认同)