我正在创建一个 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/