如果你想只得到文件的列表,并使用NULL字符为是弹性的文件名或包含\n
或:
属性,你可以这样做:
对于具有属性“列表文件合并=工会“:
git ls-files -z | git check-attr --stdin -z merge | sed -z -n -f script.sed
随着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-tree -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