【问题标题】:Git path to match any directory name匹配任何目录名称的 Git 路径
【发布时间】:2013-03-05 12:31:49
【问题描述】:

在git中我们可以使用*来指定文件名,比如*.jpg*.*,但是目录呢?

有什么方法可以指定所有目录吗?

这不起作用:

git rm firstdirectory/*/thirddirectory

* 不会产生“所有目录”效果。

【问题讨论】:

    标签: git glob


    【解决方案1】:

    您的命令不起作用,因为您正在为 git 指定一个目录。您的 shell 进行了正确的扩展,但最终 git 收到了 git rm firstdirectory/somedir/thirddirectory,这是 git 不喜欢的(git rm 需要文件)

    要使您的命令正常工作,请使用 -r 标志,然后 git 接受目录:

    git rm -r firstdirectory/*/thirddirectory
    

    【讨论】:

      【解决方案2】:

      您描述的 glob 表达式扩展不是由 git 执行的,而是由 shell 执行的。如果您执行echo * 之类的操作,您可以看到这一点。该命令接收作为文件名的参数列表 - 不是带有星号的单个参数。

      在您的情况下,find . -ipath 可能是识别您需要的路径的最有用的方法。您可能想要添加 -type d 来获取目录。 find 有许多用于选择匹配对象的选项。然后,您可以将其输入 xargs 以使用 git。例如:

      find firstdirectory -ipath 'firstdirectory/*/thirddirectory' | xargs git rm
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-08-28
        • 1970-01-01
        • 2015-10-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多