【问题标题】:Tool for ls -R in git reposgit repos 中的 ls -R 工具
【发布时间】:2013-12-12 21:58:31
【问题描述】:

我一直使用ls -R 作为一种方便的方式来查看中小型目录的结构和内容,例如我正在处理的项目,但由于@ 的存在,它变得难以使用987654322@ 在其中很多。

当有.git 时,ls -R 的前 100 行只是一个巨大的 git 索引文件和哈希列表,因此很难使用。有没有办法可以修改ls -R 或我可以使用其他工具让它只显示.git 之外的文件?最好,我仍然可以看到其他 dotfile 文件夹,但如果我不能,我会活下来。

【问题讨论】:

    标签: git unix ls


    【解决方案1】:

    你需要的是ls的-I(或--ignore)选项:ls -R -I .git

    看看manual

    ‘-I pattern’
    ‘--ignore=pattern’
        In directories, ignore files whose names match the shell pattern (not regular
        expression) pattern. As in the shell, an initial ‘.’ in a file name does not
        match a wildcard at the start of pattern. Sometimes it is useful to give this
        option several times. For example,
    
            $ ls --ignore='.??*' --ignore='.[^.]' --ignore='#*'
    
        The first option ignores names of length 3 or more that start with ‘.’, the
        second ignores all two-character names that start with ‘.’ except ‘..’, and
        the third ignores names that start with ‘#’. 
    

    【讨论】:

    • ls -R -I .git 对我不起作用。它抛出ls: illegal option -- I
    • @sortfiend 您使用的是哪个操作系统?我看到您在问题中使用了unix 标签,但 unix 存在许多变体。
    • 我有 OS X Mavericks
    • @sortfiend OS X 基于 BSD,实际上它的 ls 命令没有任何 -I 选项。我在回答中使用的摘录来自 GNU ls 的手册,该命令默认情况下在 OS X 上不可用。但是您可以安装和使用它。见Install and Use GNU Command Line Tools on Mac OS X
    【解决方案2】:

    Git 的 ls-files 有一些有用的选项。普通的git ls-files 将仅列出跟踪的文件。使用git ls-files -oc 列出所有内容。

    git ls-files -ic --exclude-standard
    

    列出与.gitignore 模式匹配的所有跟踪文件,很高兴了解这些。


    要求它只显示“被忽略”的文件,同时为其提供自定义忽略模式可能非常有用:

    git ls-files -ic -x*.pdf
    

    将向您显示所有已跟踪的 .pdf、s/ic/io/ 以获取未跟踪的 .pdf 等。Check out its docs,您可以 [ab] 以各种有用的方式使用其排除变体。

    【讨论】:

      【解决方案3】:

      一种可能是使用find

      find . -path ./.git -prune -o -print
      

      【讨论】:

        猜你喜欢
        • 2015-12-04
        • 2022-10-02
        • 2011-01-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-06-08
        • 2013-11-21
        相关资源
        最近更新 更多