【问题标题】:GIT : Search for all directories containing lower case namesGIT:搜索所有包含小写名称的目录
【发布时间】:2012-06-04 00:29:03
【问题描述】:

我在 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

【问题讨论】:

    标签: git


    【解决方案1】:

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

    1. git config --global core.ignorecase true(全局设置)
    2. git config core.ignorecase true(针对特定存储库)

    【讨论】:

    • 谢谢 Burhan...还有一个问题...我怎样才能在我的 GIT 存储库中获取所有提交中所有目录的名称都小写的列表?
    • 我对 GIT 非常陌生。所以,没有完全得到你的解决方案。我在 Windows 上使用 GIT 而不是 msysgit。您能否提供一个示例语法,用于在所有提交中搜索具有小写名称的目录列表的完整分支?
    【解决方案2】:

    This thread 可能有助于检测所有相同的路径,除了它们的情况:

    你可以这样做:

    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> 的优点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-29
      • 2015-07-16
      • 1970-01-01
      • 1970-01-01
      • 2015-06-15
      • 2015-12-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多