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

标签 git filter

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

相关文章:

asp.net-mvc - 点网 MVC 5.gitignore

c# - 如何阻止带有过滤器集的 DataGridView 在列表中移动得太远?

filter - Hbase 0.94 中的列值范围过滤器

git - 将丑陋的代码提交到 git 存储库的约定是什么?

git - 如何让 git 覆盖未发现的本地更改?

r - 过滤至少具有两个特定值的行

mysql - 如何正确使用不同的 group_concat - MYSQL

java - Apache CollectionUtil 过滤器列表包含枚举列表单词

git - svn 到 git 迁移 : incomplete history

javascript - 在 : Internal database vs. git javascript 项目中管理 JSON 文件的架构