我有一个正在处理的文件,然后意识到我在工作位置上方的几行中有一个错误。我很快改正了这个错误,并想在完成其余工作之前先将其提交。很好,这是git add --patch出现的地方!
[除了,我只看到一个结合了两个变化的大块头。是否可以手动告诉git我想要两个帅哥?
除了'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
[git gui
将允许您提交单行,即使它们被您不想提交的其他已修改的行所包围。
使用Git 2.25(2020年第1季度),继续将“ git-add--interactive
” Perl脚本移至C的工作。
结果,块分割功能(使用's'键访问的块分割功能)将发生变化。
请参见commit 2e40831,commit 54d9d9b,commit ade246e,commit d6cf873,commit 9254bdf,commit bcdd297,commit b38dd9e,commit 11f2c0d,commit 510aeca,commit 0ecd9d2,commit 5906d5d,commit 47dc4fd ,commit 80399ae,commit 7584dd3,commit 12c24cf,commit 25ea47a,commit e3bd11b,commit 1942ee4,commit f6aa7ec(2019年12月13日)之前为Johannes Schindelin (dscho
)。[[在dscho
中由Junio C Hamano -- gitster
--合并,2019年12月25日
[
gitster
:实现大块拆分功能签名人:Johannes Schindelin
如果此开发人员的工作流程有任何指示,则这是Git交互式commit 45b96a6命令的最有用的功能。注意:再次,这不是从Perl代码到C的逐字转换:例如,
首先解析diff。built-in add -p
函数实际上完成了拆分大块的所有工作,只是为了找出是否有多个大块具有结果(然后将结果扔进垃圾箱)。在C语言中,我们改为计算生成的块的数量(实际上不做拆分工作,而只是计算从非上下文行到上下文行的转换),并将该信息存储在块中,然后我们进行<[另一个偏差:内置
built-in add -p
设计时考虑到单个strbuf记住了差异(如果需要,另一个则保存了有色差异),并且块基本上只存储开始和结束偏移量指向那个strbuf。结果,当我们分割块时,我们现在使用一种特殊的模式,其中块头是动态生成的,并且只有其余的块使用这种开始/结束偏移量来存储。这样,我们还避免了Perl版本的Hunk标头的频繁格式化/重新解析。