我可以修改git-add的块大小吗?

问题描述 投票:28回答:3

我有一个正在处理的文件,然后意识到我在工作位置上方的几行中有一个错误。我很快改正了这个错误,并想在完成其余工作之前先将其提交。很好,这是git add --patch出现的地方!

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

git patch add
3个回答
46
投票

除了'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

11
投票

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


0
投票

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

结果,块分割功能(使用's'键访问的块分割功能)将发生变化。

请参见commit 2e40831commit 54d9d9bcommit ade246ecommit d6cf873commit 9254bdfcommit bcdd297commit b38dd9ecommit 11f2c0dcommit 510aecacommit 0ecd9d2commit 5906d5dcommit 47dc4fdcommit 80399aecommit 7584dd3commit 12c24cfcommit 25ea47acommit e3bd11bcommit 1942ee4commit f6aa7ec(2019年12月13日)之前为Johannes Schindelin (dscho)[[在dscho中由Junio C Hamano -- gitster --合并,2019年12月25日

[gitster:实现大块拆分功能

签名人:Johannes Schindelin

如果此开发人员的工作流程有任何指示,则这是Git交互式commit 45b96a6命令的最有用的功能。注意:再次,这不是从Perl代码到C的逐字转换:例如,built-in add -p函数实际上完成了拆分大块的所有工作,只是为了找出是否有多个大块具有结果(然后将结果扔进垃圾箱)。在C语言中,我们改为计算生成的块的数量(实际上不做拆分工作,而只是计算从非上下文行到上下文行的转换),并将该信息存储在块中,然后我们进行<

首先解析diff。

[另一个偏差:内置built-in add -p设计时考虑到单个strbuf记住了差异(如果需要,另一个则保存了有色差异),并且块基本上只存储开始和结束偏移量指向那个strbuf。结果,当我们分割块时,我们现在使用一种特殊的模式,其中块头是动态生成的,并且只有其余的块使用这种开始/结束偏移量来存储。这样,我们还避免了Perl版本的Hunk标头的频繁格式化/重新解析。

© www.soinside.com 2019 - 2024. All rights reserved.