git check-attr
允许我检查在 .gitattributes
中是否为一组特定的文件设置了属性。
例如:
# git check-attr myAttr -- org/example/file1 org/example/file2
org/example/file1: myAttr: set
org/example/file2: myAttr: unspecified
有没有一种简单的方法可以列出所有具有myAttr
设置的文件,包括所有通配符匹配?
git check-attr
允许我检查在 .gitattributes
中是否为一组特定的文件设置了属性。
例如:
# git check-attr myAttr -- org/example/file1 org/example/file2
org/example/file1: myAttr: set
org/example/file2: myAttr: unspecified
有没有一种简单的方法可以列出所有具有myAttr
设置的文件,包括所有通配符匹配?
git ls-files | git check-attr -a --stdin
您可以使用git ls-files
将包含您存储库中所有文件的列表作为参数进行设置,如下所示:
git check-attr myAttr `git ls-files`
git ls-files | xargs git check-attr myAttr
git ls-files | xargs git check-attr myAttr | grep -v 'unspecified$'
\n
或 :
的文件名或属性,你可以这样做:git ls-files -z | git check-attr --stdin -z merge | sed -z -n -f script.sed
# read filename
x # save filename in temporary space
n # read attribute name and discard it
n # read attribute name
s/^union$// # check if the value of the attribute match
t print # in that case goto print
b # otherwise goto the end
:print
x # restore filename from temporary space
p # print filename
# start again
使用内联的sed脚本(即使用-e
而不是-f
,忽略注释并将换行符替换为分号)的相同操作:
git ls-files -z | git check-attr --stdin -z merge | sed -zne 'x;n;n;s/^union$//;t print;b;:print;x;p'
PS:该结果使用 NUL 字符分隔文件名,使用 | xargs --null printf "%s\n"
以便以人类可读的方式打印它们。
git check-attr
功能,列出所有已设置属性的文件。 - StackUnderflow