【问题标题】:Alternative to git ls-tree -r HEAD -- . :!foo替代 git ls-tree -r HEAD -- 。 :!foo
【发布时间】:2015-12-04 20:54:39
【问题描述】:

我想在一组路径中检索文件的路径、权限和内容哈希列表以进行修订,不包括某些路径。

git ls-tree 看起来很完美。例如,在 Git 存储库中,

$ git ls-tree -r v2.2.2 -- Documentation ':!Documentation/RelNotes'
100644 blob ddb030137d54ef3fb0ee01d973ec5cee4bb2b2b3    Documentation/.gitattributes
100644 blob 2c8b2d612ee0d6c1f687bfa062bb7fe6471d9280    Documentation/.gitignore
100644 blob 894546dd75416fcf09542096a67b2f22a7d0de7a    Documentation/CodingGuidelines
100644 blob 2f6b6aabd74a24abdb3ac189118095fcee19f8d2    Documentation/Makefile
100644 blob fa71b5f0b62f43483d02c24d809e6282fa49576a    Documentation/SubmittingPatches
100644 blob 2c16c536ba830ec12bbf335d09f689d23e325197    Documentation/asciidoc.conf
100644 blob 0cebc4f6927211ffbc013de9368f03f480dba65d    Documentation/blame-options.txt
100755 blob ba4205e0302a267a5da6bef504f3e69eb0c4aa6d    Documentation/build-docdep.perl
100755 blob 87437f8a95768595e040b8c4c1d48e5c29ada087    Documentation/cat-texi.perl

但这是 2.3.0 中的 removed,带有消息

ls-tree: 禁用负路径规范,因为它不受支持

嗯,这是循环的;)


在 git 2.3.0 及更高版本中执行此操作的新“正确”方法是什么?

【问题讨论】:

  • (我在该消息中读到“支持”的意思是“任何人都愿意修复错误和维护代码路径的功能”,这使得它比其他情况更不循环)。
  • ...确实,更改日志表明情况确实如此:解析器接受了负路径规范,但实际上并没有工作。
  • @CharlesDuffy,他们确实奏效了,或者至少我作为 git repo 示例给出的那个有效。
  • 然而最先实现它们的人却说他们没有。说到这——邮件列表是公开的;为什么不去那里查询?
  • @CharlesDuffy,我做到了。 "向以下收件人发送永久失败:git@vger.kernel.org"

标签: git git-ls-tree


【解决方案1】:

通过管道

awk '$4 !~ /Documentation\/RelNotes/ { print }'

...是显而易见的方法。为了使其更通用:

s='Documentation/RelNotes'
awk -v exclusion_re="$s" '$4 !~ exclusion_re { print }

【讨论】:

  • ...除非您碰巧是那些使用 Windows 的可怜人之一。
  • 好吧,我用的是 Ubuntu。我只是指出其他人可能遇到的 Windows 问题。我不知道 awk 包括在内。
  • 啊。幸运的是,Windows 版 Git 是在 Windows 上运行 Git 的首选方式,它捆绑了 awk 的 msys 构建,所以......我们就这样了。
猜你喜欢
  • 2017-09-10
  • 2014-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-21
  • 2015-04-17
  • 2023-03-26
  • 2018-04-24
相关资源
最近更新 更多