然而,我只看到一个 hunk 包含了两个修改。是否有办法手动告诉 git 我需要拆成两个 hunks?
除了“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
s
。 - Jason Kimgit gui
可以让你提交单个代码行,即使它们被其他修改过的代码行包围,你也不需要将这些代码一并提交。
随着 Git 2.25(2020 年第一季度)的推出,“git-add--interactive
” Perl 脚本转换为 C 的工作正在继续。
因此,块分割功能(使用 's' 键访问的功能)将发生变化。
请查看提交2e40831, 提交54d9d9b, 提交ade246e, 提交d6cf873, 提交9254bdf, 提交bcdd297, 提交b38dd9e, 提交11f2c0d, 提交510aeca, 提交0ecd9d2, 提交5906d5d, 提交47dc4fd, 提交80399ae, 提交7584dd3, 提交12c24cf, 提交25ea47a, 提交e3bd11b, 提交1942ee4, 提交f6aa7ec (2019年12月13日) 由Johannes Schindelin (dscho
)提交。
(由Junio C Hamano -- gitster
--合并于提交45b96a6, 2019年12月25日)
内置 add -p
:实现块分割功能签名者:Johannes Schindelin
如果这位开发人员的工作流程可以说明什么问题,那么Git交互式add
命令中最有用的功能就是它。
注意:再次声明,这不是从Perl代码直接转换成C代码:例如,hunk_splittable()
函数基本上完成了所有的分割工作,只是为了找出是否会产生多个块(然后把该结果丢到垃圾堆里)。
在C语言中,我们通过计算产生的补丁块数(而不是实际进行块分割),并将该信息存储在块中,同时在第一次解析差异时进行计算。
另一个偏差:内置的git add -p
命令设计时只考虑了单个strbuf持有差异(如果请求了彩色差异,则另一个strbuf持有彩色差异),块基本上只存储指向该strbuf的起始和结束偏移量。
因此,当我们拆分块时,我们现在使用一种特殊模式,其中块标题动态生成,只有其余部分使用这种起始/结束偏移量存储。这样,我们也避免了Perl版本中块标题的频繁格式化/重新解析。