7

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すべてのワイルドカードの一致を含め、設定されているすべてのファイルを一覧表示する簡単な方法はありますか?

4

3 に答える 3

5

git ls-files次のように、 を使用して、リポジトリ内のすべてのファイルのリストを引数として設定できます。

git check-attr myAttr `git ls-files`

リポジトリにファイルが多すぎる場合、次のエラーが発生する可能性があります。

-bash: /usr/bin/git: 引数リストが長すぎます

xargsで克服できます:

git ls-files | xargs git check-attr myAttr

最後に、ファイルが多すぎる場合は、出力を読みやすくするために、引数を指定しなかったファイルを除外することをお勧めします。

git ls-files | xargs git check-attr myAttr | grep -v 'unspecified$'

grep を使用すると、必要なファイルだけに一致させるために、この出力にさらにフィルターを適用できます。

于 2015-05-02T12:03:58.467 に答える
1

ファイルのリストのみを取得し、\nまたはを含むファイル名または属性に回復力を持たせるために NUL 文字を使用する:場合は、次のようにします。

属性「merge=union」を持つファイルのリスト:

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"してファイル名を区切ります。人間が読める方法で出力するために使用します。

于 2015-06-01T12:17:51.647 に答える