【问题标题】:Why is split option missing in git add -p?为什么 git add -p 中缺少拆分选项?
【发布时间】:2016-10-28 01:05:40
【问题描述】:

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

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

Git 版本:1.9.1。 Xubuntu 14,哦,我的-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

【问题讨论】:

  • 我相信你必须先进入交互模式(-i)才能使用split。
  • 立即尝试了,但遗憾的是 - 效果相同。 IIRC git add -p 只是绕过用于选择选项的原始窗口,它直接跳转到修补程序。文档也这么说(现在检查)。不过还是谢谢。
  • 使用 Git 2.17(2018 年第二季度)会更容易,它将显示更精确的帮助消息。见my answer below

标签: git git-add


【解决方案1】:

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

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

commit 4bdd6e7commit 88f6ffccommit 01a6966(2018 年 2 月 13 日)Phillip Wood (phillipwood)
(由 Junio C Hamano -- gitster -- 合并于 commit 60f8b89,2018 年 3 月 6 日)

第一:

add -p:改进错误信息

如果用户按下当前未激活的键,请解释原因 它不是活动的,而不仅仅是列出所有键。它已经做到了 这对于某些键,此补丁对那些 尚未处理。

还有:

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

如果用户按下了add -p 没有预料到的键,那么它会打印 键绑定列表。
尽管提示仅列出了活动绑定,但为所有绑定打印了帮助。

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

【讨论】:

  • 点赞!我会按原样接受,因为我相信现在会有更多的人从中受益。不过还是谢谢@VonC!
  • @LIttleAncientForestKami 我同意:接受的答案仍然是正确的。
【解决方案2】:

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

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

【讨论】:

  • 啊!确实,未更改的行将更改的行分开。在这种情况下,我将在没有 git 的情况下拆分内容并将其部分添加。 /我谢谢!
猜你喜欢
  • 2011-08-23
  • 2012-08-07
  • 2019-02-18
  • 1970-01-01
  • 2012-07-17
  • 2019-12-30
  • 2014-08-06
相关资源
最近更新 更多