2

我在 Windows 上使用 GIT。如何在包含小写目录名称的所有提交中搜索存储库中的目录?示例我有以下文件

  • Test1\MyDirectory\Testfile.txt
  • test2\mydirectory\Testfile.txt
  • Test3\mydirectory\Testfile.txt
  • test4\mydirectory\Testfile.txt
  • test5\mydirectory\Testfile.txt

搜索应返回以下结果。

  • test2\mydirectory\Testfile.txt
  • test4\mydirectory\Testfile.txt
  • test5\mydirectory\Testfile.txt
4

2 回答 2

0

你可以告诉 git 忽略大小写不匹配:

  1. git config --global core.ignorecase true(全局设置)
  2. git config core.ignorecase true(对于特定的存储库)
于 2012-05-29T05:55:30.753 回答
0

此线程可能有助于检测所有相同的路径,但它们的情况除外:

你可以做:

git ls-files | tr A-Z a-z | sort | uniq -d

但:

  1. 它只会打印小写版本,而不是所有版本。
  2. 它不处理带有嵌入换行符的文件名。

您可以通过以下方式修复两者:

  git ls-files -z | perl -0ne '
    push @{$h{lc($_)}}, $_;
    END {
      print join("\n", @{$h{$_}}) . "\n\n"
        foreach grep { @{$h{$_}} > 1 } keys(%h);
    }
  '

线程的其余部分讨论git ls-files(可能很慢)与 git ls-tree -r <commit>.

于 2012-06-03T16:29:03.523 回答