【问题标题】:Git blame with wildcard带通配符的 Git 责备
【发布时间】:2015-07-28 11:49:25
【问题描述】:

我的存储库中有一个文件,我想对其使用 git blame,但我不确定它的路径是什么。

我已经设法像这样使用 git log:

git log -- '**/somefile'

但我似乎无法对 git blame 做同样的事情。有可能吗?

如果相关,我正在使用 mysysgit(git 版本:1.9.5.msysgit.1)。

【问题讨论】:

    标签: git wildcard msysgit


    【解决方案1】:

    你必须先找到文件:

    git ls-files -- '**/somefile'
    

    然后在返回的路径上使用git blame

    【讨论】:

    • git ls-files -- '**/somefile' | xargs git blame 应该是最好的解决方案。
    • git blame 不接受多个文件,如果您将它与xargs 一起使用,您需要告诉它一次只传递一个文件:git ls-files -- '**/somefile' | xargs -n1 git blame
    【解决方案2】:

    这在 OS X 上的 Bash 中对我来说很好用:

    git blame -- **/foo.json
    

    我不得不去掉引号才能让它工作......

    【讨论】:

    • 这是一个shell扩展,与git无关。
    • 对我不起作用。我收到一个错误:“致命:HEAD 中没有这样的路径 '**/somefile'
    • 你可能没有启用它,你可以通过shopt globstar检查
    • 双星全局扩展发生在 1) 两颗星未引用 和 2) globstar 如@MatthewBuckett 所说启用。结果是:如果一个或多个文件与 glob 匹配,则 glob 参数将替换为所有匹配的文件(我认为每个文件都用空格分隔),或者,如果没有文件与 glob 匹配,则参数不变,这解释了 OP 得到的错误 fatal: no such path '**/somefile' in HEAD:没有文件与 shell 扩展匹配,所以 Git 确实收到了 **/somefile 作为参数,Git 也找不到。
    猜你喜欢
    • 2017-04-17
    • 2011-07-03
    • 2020-12-12
    • 2016-04-21
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 2015-09-21
    相关资源
    最近更新 更多