代码之家  ›  专栏  ›  技术社区  ›  Dustin Ingram

配置“git add-p”来拆分换行符上的大块头?

git
  •  0
  • Dustin Ingram  · 技术社区  · 5 年前

    $ cat file.txt
    foo
    
    bar
    

    $ git diff
    diff --git a/file.txt b/file.txt
    index e69de29..2db72cd 100644
    --- a/file.txt
    +++ b/file.txt
    @@ -0,0 +1,3 @@
    +foo
    +
    +bar
    

    尝试添加 -p 而分割这个大块头失败了:

    $ git add -p file.txt
    diff --git a/file.txt b/file.txt
    index e69de29..2db72cd 100644
    --- a/file.txt
    +++ b/file.txt
    @@ -0,0 +1,3 @@
    +foo
    +
    +bar
    (1/1) Stage this hunk [y,n,q,a,d,e,?]? s
    Sorry, cannot split this hunk
    @@ -0,0 +1,3 @@
    +foo
    +
    +bar
    (1/1) Stage this hunk [y,n,q,a,d,e,?]?
    

    我可以配置git让我在换行时拆分这个大块头吗?

    我知道我可以编辑补丁,但我想避免。

    奖金: 我可以配置git以允许我在减少换行数时拆分吗?一、 例如,首先在双换行上拆分,然后是单换行?

    0 回复  |  直到 5 年前