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

时间:2009-07-13 21:34:28

标签: git patch add

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

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

3 个答案:

答案 0 :(得分:45)

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

答案 1 :(得分:10)

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

答案 2 :(得分:0)

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

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

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

  

commit 45b96a6:实现大块拆分功能

     

签名人:Johannes Schindelin

     

如果可以指示开发人员的工作流程,那么这是Git交互式add命令最有用的功能。

     

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

     

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