【问题标题】:Can I modify git-add's hunk size?我可以修改 git-add 的块大小吗?
【发布时间】:2010-11-10 11:14:39
【问题描述】:

我有一个我一直在处理的文件,然后我意识到我在上面几行我一直在处理的地方有一个错误。我很快纠正了这个错误,并想在我提交其余的工作之前提交它。太好了,这就是 git add --patch 的用武之地!

除了,我只看到了一个包含这两种变化的大块头。是否可以手动告诉 git 我想要两个帅哥?

【问题讨论】:

  • @Geremia 哇,递归链接!
  • 感谢您提供的有用链接,@Geremia,正是我想要的。 Git 似乎认为我的终端的行数比它多,你不能在补丁模式下滚动。

标签: git patch add


【解决方案1】:

除了 'y' 和 'n',当它询问你一个大块时,你可以给出的答案之一是'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 and all the remaining hunks in the file
d - do not stage this hunk nor any of the remaining 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

【讨论】:

  • 如果你真的需要控制试试'e'直接编辑补丁。这样您甚至可以更改补丁内容(不仅仅是选择补丁的一部分)。
  • TLDR:为了缩小块,我使用s
  • 当我按 s 时,它只是不断地给我上面的列表。不确定它没有得到“s”的哪个部分。
【解决方案2】:

git gui 将允许您提交单行,即使它们被您不想提交的其他修改行包围。

【讨论】:

  • 你也可以用 git cola 做同样的事情。
【解决方案3】:

使用 Git 2.25(2020 年第一季度),将“git-add--interactive”Perl 脚本移至 C 的工作仍在继续。

因此,大块拆分功能(使用 's' 键访问的功能)将发生变化。

commit 2e40831commit 54d9d9bcommit ade246ecommit d6cf873commit 9254bdfcommit bcdd297commit b38dd9ecommit 11f2c0dcommit 11f2c0dcommit 510aeca、@9876543321、@、@9876543321 @、commit 80399aecommit 7584dd3commit 12c24cfcommit 25ea47acommit e3bd11bcommit 1942ee4commit f6aa7ec(2019 年 12 月 13 日)by Johannes Schindelin (dscho)
(由@98764 合并@in commit 45b96a6,2019 年 12 月 25 日)

built-in add -p:实现大块拆分功能

签字人:约翰内斯·辛德林

如果此开发人员的工作流程有任何迹象,那么这是 Git 的交互式 addcommand 中最有用的功能。

注意:再一次,这不是从 Perl 代码到 C 的逐字转换:例如,hunk_splittable() 函数基本上完成了拆分大块的所有工作,只是为了找出是否有多个大块已经是结果(然后将该结果扔进垃圾箱)。
在 C 中,我们计算生成的大块的数量(实际上没有进行拆分工作,而只是计算从非上下文行到上下文行的转换),并将该信息与大块一起存储,我们这样做 首先解析差异。

另一个偏差:内置 git add -p 设计时考虑了一个保存差异的 strbuf(如果需要,另一个保存彩色差异),并且大块头基本上只存储开始和结束指向该 strbuf 的偏移量。
因此,当我们拆分大块时,我们现在使用一种特殊的模式,其中大块头是动态生成的,并且只有大块的其余部分使用这样的开始/结束偏移量来存储。这样,我们也避免了 Perl 版本的大块头的频繁格式化/重新解析。

【讨论】:

    猜你喜欢
    • 2016-02-26
    • 2019-12-23
    • 2019-05-21
    • 2017-10-28
    • 2022-11-12
    • 2011-02-07
    • 2020-06-28
    • 2013-08-04
    • 2020-01-02
    相关资源
    最近更新 更多