Git查找被Smudge/Clean过滤器过滤的文件的文件名

3

我正在创建一个模糊/清理 Git 过滤器。该过滤器将需要知道被过滤的文件名,以便可以执行一些外部操作,其结果将由过滤器输出。

由于过滤器从 stdin 读取并写入到 stdout,是否有任何方法可以获取被过滤的文件名?

例如,我想要:

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

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

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

用于测试文件是否为二进制的方法。

然而,我需要知道在过滤器内部应该使用什么作为"$0"才能使其起作用?

1个回答

8

From the 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 是你想要的。

那看起来就像我在找的东西。我会测试并告诉你。 - MERM

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接