【问题标题】:Why doesn't git add --patch work with git add -N of a binary file?为什么 git add --patch 不能与二进制文件的 git add -N 一起使用?
【发布时间】:2018-09-11 12:06:19
【问题描述】:

git add --patch 不适用于使用git add -N 添加的二进制文件。有谁知道为什么?在下面的示例中,您可以看到git add --patch 选择了文本文件a,但没有选择二进制文件0

echo a > a
echo '\0' > 0
git add -N 0
git add -N a

git add --patch
diff --git a/a b/a
index e69de29..7898192 100644
--- a/a
+++ b/a
@@ -0,0 +1 @@
+a
Stage this hunk [y,n,q,a,d,/,e,?]? y 

【问题讨论】:

    标签: git binaryfiles git-add


    【解决方案1】:

    该实现明确排除了二进制文件。见第 7 行:

     1  sub patch_update_cmd {
     2    my @all_mods = list_modified($patch_mode_flavour{FILTER});
     3    error_msg sprintf(__("ignoring unmerged: %s\n"), $_->{VALUE})
     4      for grep { $_->{UNMERGED} } @all_mods;
     5    @all_mods = grep { !$_->{UNMERGED} } @all_mods;
     6
     7    my @mods = grep { !($_->{BINARY}) } @all_mods;
     8    my @them;
     9
    10    if (!@mods) {
    11      if (@all_mods) {
    12        print STDERR __("Only binary files changed.\n");
    13      } else {
    14        print STDERR __("No changes.\n");
    15      }
    16      return 0;
    17    }
    18    if ($patch_mode_only) {
    19      @them = @mods;
    20    }
    21    else {
    22      @them = list_and_choose({ PROMPT => __('Patch update'),
    23              HEADER => $status_head, },
    24            @mods);
    25    }
    26    for (@them) {
    27      return 0 if patch_update_file($_->{VALUE});
    28    }
    29  }
    

    git-add--interactive.perl#L1310-L1338

    【讨论】:

    • 有趣。知道为什么吗?
    • 自2006年引入命令(commit 5cde71d64aff)以来一直如此。我只能推测为什么——也许是因为补丁添加二进制文件没有意义,因为它不能被分割成块。
    猜你喜欢
    • 2016-06-23
    • 2020-07-08
    • 2013-01-07
    • 1970-01-01
    • 2013-07-17
    • 2020-08-11
    • 1970-01-01
    • 2018-08-10
    • 2023-02-23
    相关资源
    最近更新 更多