gpt4 book ai didi

git 查找被 smudge/clean 过滤器过滤的文件的文件名

转载 作者:太空狗 更新时间:2023-10-29 14:33:17 27 4
gpt4 key购买 nike

我正在创建一个 smudge/clean git 过滤器。过滤器需要知道名称被过滤的文件,以便它可以执行一些外部操作其结果将由过滤器输出。

由于过滤器是从标准输入读取并写入标准输出,有没有办法获取被过滤的文件名?

例如我想:

git blame $0  | cut -d " " -f 4-6 | sort | uniq | sort | tail -1

找出此文件的最后更改日期或:

git grep -I --name-only -e "" -- $0

测试文件是否为二进制文件。

但是,我需要知道我应该使用什么作为“$0”才能在过滤器内部完成这项工作?

最佳答案

来自 gitattributes manual

Sequence "%f" on the filter command line is replaced with the name of the file the filter is working on. A filter might use this in keyword substitution. For example:

[filter "p4"]

   clean = git-p4-filter --clean %f
smudge = git-p4-filter --smudge %f

也许 %f 就是您想要的。

关于git 查找被 smudge/clean 过滤器过滤的文件的文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17004887/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com