gitattributes

NAME

gitattributes - Defining attributes per pathgitattributes - パスごとの属性の定義

SYNOPSIS概要

$GIT_DIR/info/attributes, .gitattributes$ GIT_DIR / info / attributes、.gitattributes

DESCRIPTION説明

A gitattributes file is a simple text file that gives attributes to pathnames.gitattributesファイルが与えられる単純なテキストファイルでattributesパス名に。

Each line in gitattributes file is of form:各行gitattributesファイルの形式は次のとおりです。

pattern	attr1 attr2 ...

That is, a pattern followed by an attributes list, separated by whitespaces. Leading and trailing whitespaces are ignored. Lines that begin with # are ignored. Patterns that begin with a double quote are quoted in C style. When the pattern matches the path in question, the attributes listed on the line are given to the path.つまり、空白文字で区切られたパターンとそれに続く属性リストです。先頭と末尾の空白は無視されます。で始まる行は無視されます。二重引用符で始まるパターンはCスタイルで引用されます。パターンが問題のパスと一致すると、その行にリストされている属性がそのパスに与えられます。

Each attribute can be in one of these states for a given path:各属性は、特定のパスに対して次のいずれかの状態になります。

Set セット

The path has the attribute with special value "true"; this is specified by listing only the name of the attribute in the attribute list.パスは特別な値 "true"を持つ属性を持ちます。これは、属性リスト内の属性の名前のみをリストすることによって指定されます。

Unset 未設定

The path has the attribute with special value "false"; this is specified by listing the name of the attribute prefixed with a dash - in the attribute list.パスは特別な値 "false"を持つ属性を持ちます。これは-、属性リストの先頭にダッシュが付いた属性の名前をリストすることによって指定されます。

Set to a value 値に設定

The path has the attribute with specified string value; this is specified by listing the name of the attribute followed by an equal sign = and its value in the attribute list.パスは指定された文字列値を持つ属性を持ちます。これは、属性の名前の後に等号=とその値を続けて属性リストにリストすることによって指定されます。

Unspecified 指定なし

No pattern matches the path, and nothing says if the path has or does not have the attribute, the attribute for the path is said to be Unspecified.パスに一致するパターンはなく、パスに属性があるかどうかに関係なく、パスの属性は未指定とは言えません。

When more than one pattern matches the path, a later line overrides an earlier line. This overriding is done per attribute.複数のパターンがパスに一致すると、後の行が前の行をオーバーライドします。この上書きは属性ごとに行われます。

The rules by which the pattern matches paths are the same as in .gitignore files (see gitignore[5]), with a few exceptions:パターンがパスと一致する規則は、いくつかの例外を除いて.gitignoreファイルと同じです(gitignore [5]を参照)。

  • negative patterns are forbidden否定的なパターンは禁止されています

  • patterns that match a directory do not recursively match paths inside that directory (so using the trailing-slash path/ syntax is pointless in an attributes file; use path/** instead)ディレクトリと一致するパターンは、そのディレクトリ内のパスと再帰的には一致しません(したがって、末尾スラッシュpath/構文を使用しても属性ファイルでは意味がありません。path/**代わりに使用してください)

When deciding what attributes are assigned to a path, Git consults $GIT_DIR/info/attributes file (which has the highest precedence), .gitattributes file in the same directory as the path in question, and its parent directories up to the toplevel of the work tree (the further the directory that contains .gitattributes is from the path in question, the lower its precedence). Finally global and system-wide files are considered (they have the lowest precedence).どの属性がパスに割り当てられるかを決定するとき、Gitは$GIT_DIR/info/attributesファイル(最も高い優先順位を持つ)、.gitattributes問題のパスと同じディレクトリにあるファイル、そして作業ディレクトリのトップレベルまでの親ディレクトリ(さらにそのディレクトリ)を調べます。contains .gitattributesは問題のパスからのもので、優先順位が低いものです。最後に、グローバルファイルとシステム全体のファイルが考慮されます(優先順位が最も低くなります)。

When the .gitattributes file is missing from the work tree, the path in the index is used as a fall-back. During checkout process, .gitattributes in the index is used and then the file in the working tree is used as a fall-back..gitattributesファイルが作業ツリーにない場合は、インデックス内のパスが代替として使用されます。チェックアウトプロセス中.gitattributesに、インデックスが使用され、次に作業ツリー内のファイルがフォールバックとして使用されます。

If you wish to affect only a single repository (i.e., to assign attributes to files that are particular to one user’s workflow for that repository), then attributes should be placed in the $GIT_DIR/info/attributes file. Attributes which should be version-controlled and distributed to other repositories (i.e., attributes of interest to all users) should go into .gitattributes files. Attributes that should affect all repositories for a single user should be placed in a file specified by the core.attributesFile configuration option (see git-config[1]). Its default value is $XDG_CONFIG_HOME/git/attributes. If $XDG_CONFIG_HOME is either not set or empty, $HOME/.config/git/attributes is used instead. Attributes for all users on a system should be placed in the $(prefix)/etc/gitattributes file.単一のリポジトリのみに影響を与えたい場合(つまり、そのリポジトリに対する1人のユーザーのワークフローに固有のファイルに属性を割り当てる場合)は、属性を$GIT_DIR/info/attributesファイルに配置する必要があります。バージョン管理され、他のリポジトリに配布されるべき属性(すなわち、すべてのユーザにとって関心のある属性)は.gitattributesファイルに入れるべきです。1人のユーザーのすべてのリポジトリに影響を与えるべき属性は、core.attributesFile設定オプションで指定されたファイルに置かれるべきです(git-config [1]を参照)。デフォルト値は$ XDG_CONFIG_HOME / git / attributesです。$ XDG_CONFIG_HOMEが設定されていないか空の場合は、代わりに$ HOME / .config / git / attributesが使用されます。システム上のすべてのユーザーの属性を$(prefix)/etc/gitattributesファイルに入れる必要があります。

Sometimes you would need to override a setting of an attribute for a path to Unspecified state. This can be done by listing the name of the attribute prefixed with an exclamation point !.時々、Unspecifiedstate へのパスに対する属性の設定を上書きする必要があるでしょう。これは、感嘆符を前に付けて属性の名前をリストすることによって行うことができます!

EFFECTS効果

Certain operations by Git can be influenced by assigning particular attributes to a path. Currently, the following operations are attributes-aware.Gitによる操作の中には、パスに特定の属性を割り当てることによって影響を受けるものがあります。現在、以下の操作は属性に対応しています。

Checking-out and checking-inチェックアウトとチェックイン

These attributes affect how the contents stored in the repository are copied to the working tree files when commands such as git checkout and git merge run. They also affect how Git stores the contents you prepare in the working tree in the repository upon git add and git commit.これらの属性は、git checkoutgit mergeなどのコマンド実行されたときに、リポジトリに格納されているコンテンツが作業ツリーファイルにコピーされる方法に影響ます。また、git addgit commitの際に、Gitがあなたが作成したコンテンツをリポジトリの作業ツリーにどのように保存するかにも影響します。

text

This attribute enables and controls end-of-line normalization. When a text file is normalized, its line endings are converted to LF in the repository. To control what line ending style is used in the working directory, use the eol attribute for a single file and the core.eol configuration variable for all text files. Note that setting core.autocrlf to true or input overrides core.eol (see the definitions of those options in git-config[1]).この属性は、行末正規化を有効にして制御します。テキストファイルが正規化されると、その行末はリポジトリのLFに変換されます。作業ディレクトリで使用される行末スタイルを制御するeolには、単一ファイルの属性core.eolとすべてのテキストファイルの構成変数を使用します。に設定または上書きするcore.autocrlfことに注意してください(git-config [1]のそれらのオプションの定義を参照してください)。trueinputcore.eol

Set セット

Setting the text attribute on a path enables end-of-line normalization and marks the path as a text file. End-of-line conversion takes place without guessing the content type.textパスに属性を設定すると、行末正規化が有効になり、パスがテキストファイルとしてマークされます。行末変換は、コンテンツタイプを推測せずに行われます。

Unset 未設定

Unsetting the text attribute on a path tells Git not to attempt any end-of-line conversion upon checkin or checkout.パスのtext属性を設定解除すると、チェックインまたはチェックアウト時に行末変換を試行しないようにGitに指示します。

Set to string value "auto" 文字列値 "auto"に設定

When text is set to "auto", the path is marked for automatic end-of-line conversion. If Git decides that the content is text, its line endings are converted to LF on checkin. When the file has been committed with CRLF, no conversion is done.ときはtext、「オート」に設定され、パスが自動行末変換のためにマークされています。内容がテキストであるとGitが判断した場合、その行末はチェックイン時にLFに変換されます。ファイルがCRLFでコミットされていると、変換は行われません。

Unspecified 指定なし

If the text attribute is unspecified, Git uses the core.autocrlf configuration variable to determine if the file should be converted.text属性が指定されていない場合、Gitはcore.autocrlf構成変数を使用してファイルを変換する必要があるかどうかを判断します。

Any other value causes Git to act as if text has been left unspecified.他の値を指定すると、Gitはあたかもtext指定されていないかのように振る舞います。

eol

This attribute sets a specific line-ending style to be used in the working directory. It enables end-of-line conversion without any content checks, effectively setting the text attribute. Note that setting this attribute on paths which are in the index with CRLF line endings may make the paths to be considered dirty. Adding the path to the index again will normalize the line endings in the index.この属性は、作業ディレクトリで使用される特定の行末スタイルを設定します。内容をチェックせずに行末変換を可能にし、効果的にtext属性を設定します。CRLFの行末を持つインデックス内にあるパスにこの属性を設定すると、パスがダーティと見なされる可能性があります。パスをインデックスに再度追加すると、インデックス内の行末が正規化されます。

Set to string value "crlf" 文字列値 "crlf"に設定

This setting forces Git to normalize line endings for this file on checkin and convert them to CRLF when the file is checked out.この設定により、チェックイン時にGitはこのファイルの行末を正規化し、ファイルがチェックアウトされたときにそれらをCRLFに変換します。

Set to string value "lf" 文字列値 "lf"に設定

This setting forces Git to normalize line endings to LF on checkin and prevents conversion to CRLF when the file is checked out.この設定により、チェックイン時にGitは行末をLFに正規化し、ファイルがチェックアウトされたときにCRLFに変換されないようにします。

Backwards compatibility with crlf attributecrlf属性との後方互換性

For backwards compatibility, the crlf attribute is interpreted as follows:後方互換性のために、このcrlf属性は次のように解釈されます。

crlf		text
-crlf		-text
crlf=input	eol=lf
End-of-line conversion行末変換

While Git normally leaves file contents alone, it can be configured to normalize line endings to LF in the repository and, optionally, to convert them to CRLF when files are checked out.Gitは通常ファイルの内容をそのままにしていますが、リポジトリ内で行末をLFに正規化し、オプションでファイルがチェックアウトされたときにそれらをCRLFに変換するように設定できます。

If you simply want to have CRLF line endings in your working directory regardless of the repository you are working with, you can set the config variable "core.autocrlf" without using any attributes.作業しているリポジトリに関係なく、作業ディレクトリのCRLF行の終わりを単純にしたい場合は、属性を使用せずに設定変数 "core.autocrlf"を設定できます。

[core]
	autocrlf = true

This does not force normalization of text files, but does ensure that text files that you introduce to the repository have their line endings normalized to LF when they are added, and that files that are already normalized in the repository stay normalized.これはテキストファイルの正規化を強制するものではありませんが、追加したときにリポジトリに導入するテキストファイルの行末がLFに正規化され、リポジトリ内ですでに正規化されているファイルは正規化されます。

If you want to ensure that text files that any contributor introduces to the repository have their line endings normalized, you can set the text attribute to "auto" for all files.任意の貢献者がリポジトリに紹介するテキストファイルの行末が正規化されていることを確認したい場合はtextすべてのファイルに対して属性を "auto"に設定できます。

*	text=auto

The attributes allow a fine-grained control, how the line endings are converted. Here is an example that will make Git normalize .txt, .vcproj and .sh files, ensure that .vcproj files have CRLF and .sh files have LF in the working directory, and prevent .jpg files from being normalized regardless of their content.属性によって、きめ細かい制御、つまり行末の変換方法が可能になります。これは、Gitが.txt、.vcproj、および.shファイルを正規化し、作業ディレクトリに.vcprojファイルのCRLFファイルと.shファイルのLFファイルを確実にし、その内容にかかわらず.jpgファイルが正規化されないようにする例です。

*               text=auto
*.txt		text
*.vcproj	text eol=crlf
*.sh		text eol=lf
*.jpg		-text
Note When text=auto conversion is enabled in a cross-platform project using push and pull to a central repository the text files containing CRLFs should be normalized. text=autoクロスプラットフォームプロジェクトで中央リポジトリへのプッシュアンドプルを使用して変換が有効になっている 場合は、CRLFを含むテキストファイルを正規化する必要があります。

From a clean working directory:きれいな作業ディレクトリから:

$ echo "* text=auto" >.gitattributes
$ git add --renormalize .
$ git status        # Show files that will be normalized
$ git commit -m "Introduce end-of-line normalization"

If any files that should not be normalized show up in git status, unset their text attribute before running git add -u.正規化すべきでないファイルがgitステータスで表示される場合は、git add -uをtext実行する前にそれらの属性の設定を解除してください。

manual.pdf	-text

Conversely, text files that Git does not detect can have normalization enabled manually.逆に、Gitが検出しないテキストファイルでは正規化を手動で有効にすることができます。

weirdchars.txt	text

If core.safecrlf is set to "true" or "warn", Git verifies if the conversion is reversible for the current setting of core.autocrlf. For "true", Git rejects irreversible conversions; for "warn", Git only prints a warning but accepts an irreversible conversion. The safety triggers to prevent such a conversion done to the files in the work tree, but there are a few exceptions. Even though…​core.safecrlfが "true"または "warn"に設定されている場合、Gitは現在の設定に対して変換が元に戻せるかどうかを検証しcore.autocrlfます。"true"の場合、Gitは不可逆的な変換を拒否します。"warn"の場合、Gitは警告を表示するだけで、不可逆的な変換を受け入れます。このような変換がワークツリー内のファイルに対して行われないようにするための安全性の引き金となりますが、いくつかの例外があります。それでも…

  • git add itself does not touch the files in the work tree, the next checkout would, so the safety triggers;git add自体は作業ツリー内のファイルには触れず、次のチェックアウトではそうなるので、安全性がトリガーされます。

  • git apply to update a text file with a patch does touch the files in the work tree, but the operation is about text files and CRLF conversion is about fixing the line ending inconsistencies, so the safety does not trigger;パッチを適用してテキストファイルを更新するgit applyは作業ツリー内のファイルには適用されますが、操作はテキストファイルに関するもので、CRLF変換は行末の矛盾の修正に関するものなので、安全性は作動しません。

  • git diff itself does not touch the files in the work tree, it is often run to inspect the changes you intend to next git add. To catch potential problems early, safety triggers.git diff自体は作業ツリー内のファイルには影響しません。それは、次にgit addする予定の変更を調べるために実行されることがよくあります。潜在的な問題を早期に発見するためには、安全性が必要です。

working-tree-encoding

Git recognizes files encoded in ASCII or one of its supersets (e.g. UTF-8, ISO-8859-1, …​) as text files. Files encoded in certain other encodings (e.g. UTF-16) are interpreted as binary and consequently built-in Git text processing tools (e.g. git diff) as well as most Git web front ends do not visualize the contents of these files by default.Gitは、ASCIIまたはそのスーパーセットの1つ(例:UTF-8、ISO-8859-1など)でエンコードされたファイルをテキストファイルとして認識します。他のエンコーディング(UTF-16など)でエンコードされたファイルはバイナリとして解釈され、その結果、組み込みのGitテキスト処理ツール(git diffなど)やほとんどのGit Webフロントエンドはデフォルトでこれらのファイルの内容を視覚化しません。

In these cases you can tell Git the encoding of a file in the working directory with the working-tree-encoding attribute. If a file with this attribute is added to Git, then Git reencodes the content from the specified encoding to UTF-8. Finally, Git stores the UTF-8 encoded content in its internal data structure (called "the index"). On checkout the content is reencoded back to the specified encoding.このような場合は、作業ディレクトリ内のファイルのエンコーディングをGitにworking-tree-encoding属性を付けて伝えることができます。この属性を持つファイルがGitに追加された場合、Gitは指定されたエンコーディングからUTF-8に内容を再エンコードします。最後に、GitはUTF-8でエンコードされたコンテンツを内部のデータ構造( "インデックス"と呼びます)に格納します。チェックアウト時に、コンテンツは指定されたエンコーディングに再エンコードされます。

Please note that using the working-tree-encoding attribute may have a number of pitfalls:このworking-tree-encoding属性を使用するといくつかの落とし穴があるかもしれないことに注意してください。

  • Alternative Git implementations (e.g. JGit or libgit2) and older Git versions (as of March 2018) do not support the working-tree-encoding attribute. If you decide to use the working-tree-encoding attribute in your repository, then it is strongly recommended to ensure that all clients working with the repository support it.代替のGit実装(JGitやlibgit2など)や古いGitバージョン(2018年3月現在)はこのworking-tree-encoding属性をサポートしていません。working-tree-encodingリポジトリでこの属性を使用することにした場合は、リポジトリを使用しているすべてのクライアントがそれをサポートしていることを確認することを強くお勧めします。

    For example, Microsoft Visual Studio resources files (*.rc) or PowerShell script files (*.ps1) are sometimes encoded in UTF-16. If you declare *.ps1 as files as UTF-16 and you add foo.ps1 with a working-tree-encoding enabled Git client, then foo.ps1 will be stored as UTF-8 internally. A client without working-tree-encoding support will checkout foo.ps1 as UTF-8 encoded file. This will typically cause trouble for the users of this file.たとえば、Microsoft Visual Studioのリソースファイル(*.rc)またはPowerShellスクリプトファイル(*.ps1)は、UTF-16でエンコードされていることがあります。*.ps1ファイルをUTF-16として宣言foo.ps1し、working-tree-encoding有効なGitクライアントで追加した場合、foo.ps1内部的にはUTF-8として格納されます。working-tree-encodingサポートのないクライアントfoo.ps1はUTF-8でエンコードされたファイルとしてチェックアウトします。これは通常、このファイルのユーザーに問題を引き起こします。

    If a Git client, that does not support the working-tree-encoding attribute, adds a new file bar.ps1, then bar.ps1 will be stored "as-is" internally (in this example probably as UTF-16). A client with working-tree-encoding support will interpret the internal contents as UTF-8 and try to convert it to UTF-16 on checkout. That operation will fail and cause an error.サポートされていないのGitクライアント、場合working-tree-encoding属性は、新しいファイルを追加しbar.ps1、その後、bar.ps1内部的に(この例では、おそらくUTF-16など)「であるとして、」保存されます。working-tree-encodingサポートを受けているクライアントは内部コンテンツをUTF-8として解釈し、チェックアウト時にそれをUTF-16に変換しようとします。その操作は失敗し、エラーが発生します。

  • Reencoding content to non-UTF encodings can cause errors as the conversion might not be UTF-8 round trip safe. If you suspect your encoding to not be round trip safe, then add it to core.checkRoundtripEncoding to make Git check the round trip encoding (see git-config[1]). SHIFT-JIS (Japanese character set) is known to have round trip issues with UTF-8 and is checked by default.変換はUTF-8ラウンドトリップセーフではない可能性があるため、コンテンツを非UTFエンコーディングに再エンコードするとエラーが発生する可能性があります。エンコーディングがラウンドトリップセーフではないと思われる場合は、を追加core.checkRoundtripEncodingしてGitにラウンドトリップエンコーディングをチェックさせます(git-config [1]を参照)。SHIFT-JIS(日本語文字セット)はUTF-8では往復の問題があることが知られており、デフォルトでチェックされています。

  • Reencoding content requires resources that might slow down certain Git operations (e.g git checkout or git add).コンテンツを再エンコードするには、特定のGit操作を遅くする可能性のあるリソース(git checkoutgit addなど)が必要です。

Use the working-tree-encoding attribute only if you cannot store a file in UTF-8 encoding and if you want Git to be able to process the content as text.working-tree-encodingファイルをUTF-8エンコーディングで保存できない場合、およびGitにコンテンツをテキストとして処理させたい場合にのみ、この属性を使用してください。

As an example, use the following attributes if your *.ps1 files are UTF-16 encoded with byte order mark (BOM) and you want Git to perform automatic line ending conversion based on your platform.例として、*。ps1ファイルがバイトオーダーマーク(BOM)でUTF-16でエンコードされていて、Gitがプラットフォームに基づいて自動行末変換を実行するようにする場合は、次の属性を使用します。

*.ps1		text working-tree-encoding=UTF-16

Use the following attributes if your *.ps1 files are UTF-16 little endian encoded without BOM and you want Git to use Windows line endings in the working directory (use UTF-16-LE-BOM instead of UTF-16LE if you want UTF-16 little endian with BOM). Please note, it is highly recommended to explicitly define the line endings with eol if the working-tree-encoding attribute is used to avoid ambiguity.* .ps1ファイルがBOMなしのUTF-16リトルエンディアンでエンコードされていて、Gitが作業ディレクトリでWindowsの行末を使用するようにする場合は、次の属性を使用します(BOM付きのUTF-16リトルエンディアンが必要な場合のUTF-16-LE-BOM代わりに使用しUTF-16LEます)。曖昧さを避けるために属性を使用するeol場合は、行の終わりを明示的に定義することを強くお勧めしますworking-tree-encoding

*.ps1		text working-tree-encoding=UTF-16LE eol=CRLF

You can get a list of all available encodings on your platform with the following command:次のコマンドであなたのプラットフォームで利用可能なすべてのエンコーディングのリストを得ることができます。

iconv --list

If you do not know the encoding of a file, then you can use the file command to guess the encoding:ファイルのエンコーディングがわからない場合は、fileコマンドを使用してエンコーディングを推測できます。

file foo.ps1
ident

When the attribute ident is set for a path, Git replaces $Id$ in the blob object with $Id:, followed by the 40-character hexadecimal blob object name, followed by a dollar sign $ upon checkout. Any byte sequence that begins with $Id: and ends with $ in the worktree file is replaced with $Id$ upon check-in.属性identがパスに設定されている場合、Gitは$Id$BLOBオブジェクト内で$Id:40文字の16進BLOBオブジェクト名、その後$にチェックアウト時にドル記号を続けて置き換えます。ワークツリーファイルの先頭$Id:から末尾までのバイトシーケンス$$Id$、チェックイン時に置き換えられます。

filter

A filter attribute can be set to a string value that names a filter driver specified in the configuration.filter属性は、名前設定で指定されたフィルタドライバ文字列値に設定することができます。

A filter driver consists of a clean command and a smudge command, either of which can be left unspecified. Upon checkout, when the smudge command is specified, the command is fed the blob object from its standard input, and its standard output is used to update the worktree file. Similarly, the clean command is used to convert the contents of worktree file upon checkin. By default these commands process only a single blob and terminate. If a long running process filter is used in place of clean and/or smudge filters, then Git can process all blobs with a single filter command invocation for the entire life of a single Git command, for example git add --all. If a long running process filter is configured then it always takes precedence over a configured single blob filter. See section below for the description of the protocol used to communicate with a process filter.フィルタドライバは、cleanコマンドとコマンドで構成されsmudgeます。どちらも未指定のままにできます。チェックアウト時にsmudgeコマンドが指定されると、そのコマンドはその標準入力からBLOBオブジェクトを受け取り、その標準出力を使用してワークツリーファイルを更新します。同様に、このcleanコマンドはチェックイン時にワークツリーファイルの内容を変換するために使用されます。デフォルトでは、これらのコマンドは単一のBLOBのみを処理して終了します。および/またはフィルタのprocess代わりに長時間実行フィルタが使用されている場合、Gitは、たとえば、1つのGitコマンドの有効期間全体にわたって、1つのフィルタコマンド呼び出しですべてのBLOBを処理できます。長時間走ればcleansmudgegit add --allprocessフィルタが設定されている場合は、設定されている単一のBLOBフィルタよりも常に優先されます。processフィルタと通信するために使用されるプロトコルの説明については、以下のセクションを参照してください。

One use of the content filtering is to massage the content into a shape that is more convenient for the platform, filesystem, and the user to use. For this mode of operation, the key phrase here is "more convenient" and not "turning something unusable into usable". In other words, the intent is that if someone unsets the filter driver definition, or does not have the appropriate filter program, the project should still be usable.コンテンツフィルタリングの用途の1つは、プラットフォーム、ファイルシステム、およびユーザーが使用するのに便利な形にコンテンツをマッサージすることです。この動作モードでは、ここでのキーフレーズは「より便利」であり、「使用できないものを使用可能にすること」ではありません。言い換えれば、その目的は、誰かがフィルタドライバの定義を解除したり、適切なフィルタプログラムを持っていなかったりした場合でも、プロジェクトを使用できるようにすることです。

Another use of the content filtering is to store the content that cannot be directly used in the repository (e.g. a UUID that refers to the true content stored outside Git, or an encrypted content) and turn it into a usable form upon checkout (e.g. download the external content, or decrypt the encrypted content).コンテンツフィルタリングのもう1つの用途は、リポジトリで直接使用できないコンテンツ(Gitの外部に保存されている本当のコンテンツを指すUUID、または暗号化されたコンテンツなど)をチェックアウト時に使用可能な形式に変換することです。外部コンテンツ、または暗号化されたコンテンツを復号化します。

These two filters behave differently, and by default, a filter is taken as the former, massaging the contents into more convenient shape. A missing filter driver definition in the config, or a filter driver that exits with a non-zero status, is not an error but makes the filter a no-op passthru.これら2つのフィルタは異なる動作をします。デフォルトでは、フィルタは前者として扱われ、内容をより便利な形にまとめます。設定内に不足しているフィルタドライバ定義、または0以外のステータスで終了するフィルタドライバはエラーではありませんが、フィルタを何もしないパススルーにします。

You can declare that a filter turns a content that by itself is unusable into a usable content by setting the filter.<driver>.required configuration variable to true.filter。<driver> .required設定変数をに設定することで、フィルタが単独では使用できないコンテンツを使用可能なコンテンツに変換することを宣言できますtrue

Note: Whenever the clean filter is changed, the repo should be renormalized: $ git add --renormalize .注意:cleanフィルタが変更されたときはいつでも、レポは再正規化されるべきです:$ git add --renormalize。

For example, in .gitattributes, you would assign the filter attribute for paths.たとえば、.gitattributesでは、filterパスに属性を割り当てます。

*.c	filter=indent

Then you would define a "filter.indent.clean" and "filter.indent.smudge" configuration in your .git/config to specify a pair of commands to modify the contents of C programs when the source files are checked in ("clean" is run) and checked out (no change is made because the command is "cat").それから、あなたの.git / configに "filter.indent.clean"と "filter.indent.smudge"設定を定義して、ソースファイルがチェックインされたときにCプログラムの内容を変更するためのコマンドのペアを指定します。実行され、チェックアウトされます(コマンドが "cat"であるため、変更は行われません)。

[filter "indent"]
	clean = indent
	smudge = cat

For best results, clean should not alter its output further if it is run twice ("clean→clean" should be equivalent to "clean"), and multiple smudge commands should not alter clean's output ("smudge→smudge→clean" should be equivalent to "clean"). See the section on merging below.最良の結果を得るためにclean、(「クリーン」と同等である必要があり、「クリーン→クリーン」)を2回実行され、さらに場合は、その出力を変化させてはならない、と複数smudgeのコマンドは変更しないでくださいcleanと同等でなければなりません( 『クリーン→汚れ→汚れ』の出力をきれいにするため")。下記のマージに関するセクションを参照してください。

The "indent" filter is well-behaved in this regard: it will not modify input that is already correctly indented. In this case, the lack of a smudge filter means that the clean filter must accept its own output without modifying it.「インデント」フィルタはこの点ではうまく動作します。すでに正しくインデントされている入力を変更することはありません。この場合、汚れフィルタがないということは、クリーンフィルタは修正せずに独自の出力を受け入れなければならないことを意味します。

If a filter must succeed in order to make the stored contents usable, you can declare that the filter is required, in the configuration:格納されたコンテンツを使用可能にするためにフィルタ成功する必要があるrequired場合は、設定内でフィルタが次のように宣言されています。

[filter "crypt"]
	clean = openssl enc ...
	smudge = openssl enc -d ...
	required

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:フィルタコマンドラインのシーケンス "%f"は、フィルタが動作しているファイルの名前に置き換えられます。フィルタはキーワード置換でこれを使用するかもしれません。例えば:

[filter "p4"]
	clean = git-p4-filter --clean %f
	smudge = git-p4-filter --smudge %f

Note that "%f" is the name of the path that is being worked on. Depending on the version that is being filtered, the corresponding file on disk may not exist, or may have different contents. So, smudge and clean commands should not try to access the file on disk, but only act as filters on the content provided to them on standard input."%f"は作業中のパスの名前です。フィルタ処理されているバージョンによっては、ディスク上の対応するファイルが存在しないか、内容が異なる場合があります。したがって、smudgeコマンドとcleanコマンドは、ディスク上のファイルにアクセスしようとするのではなく、標準入力で提供されたコンテンツに対するフィルタとしてのみ機能します。

Long Running Filter Process長時間フィルター処理

If the filter command (a string value) is defined via filter.<driver>.process then Git can process all blobs with a single filter invocation for the entire life of a single Git command. This is achieved by using the long-running process protocol (described in technical/long-running-process-protocol.txt).filterコマンド(文字列値)がviaで定義されているfilter.<driver>.process場合、Gitは1回のGitコマンドの有効期間中、1回のフィルター呼び出しですべてのBLOBを処理できます。これは長期実行プロセスプロトコル(technical / long-running-process-protocol.txtに記述されています)を使用することによって達成されます。

When Git encounters the first file that needs to be cleaned or smudged, it starts the filter and performs the handshake. In the handshake, the welcome message sent by Git is "git-filter-client", only version 2 is suppported, and the supported capabilities are "clean", "smudge", and "delay".Gitは、クリーンアップまたは汚す必要がある最初のファイルに出会うと、フィルタを開始してハンドシェイクを実行します。ハンドシェイクでは、Gitが送ったウェルカムメッセージは "git-filter-client"で、バージョン2のみがサポートされ、サポートされている機能は "clean"、 "smudge"、および "delay"です。

Afterwards Git sends a list of "key=value" pairs terminated with a flush packet. The list will contain at least the filter command (based on the supported capabilities) and the pathname of the file to filter relative to the repository root. Right after the flush packet Git sends the content split in zero or more pkt-line packets and a flush packet to terminate content. Please note, that the filter must not send any response before it received the content and the final flush packet. Also note that the "value" of a "key=value" pair can contain the "=" character whereas the key would never contain that character.その後Gitはフラッシュパケットで終わった "key = value"ペアのリストを送ります。このリストには、少なくともfilterコマンド(サポートされている機能に基づく)と、リポジトリルートを基準にしてフィルタをかけるファイルのパス名が含まれます。フラッシュパケットの直後にGitはコンテンツを0個以上のpkt-lineパケットとフラッシュパケットに分割して送信し、コンテンツを終了させます。フィルタは、コンテンツと最後のフラッシュパケットを受信する前に応答を送信してはなりません。また、 "key = value"のペアの "value"には "="文字を含めることができますが、キーにはその文字を含めることはできません。

packet:          git> command=smudge
packet:          git> pathname=path/testfile.dat
packet:          git> 0000
packet:          git> CONTENT
packet:          git> 0000

The filter is expected to respond with a list of "key=value" pairs terminated with a flush packet. If the filter does not experience problems then the list must contain a "success" status. Right after these packets the filter is expected to send the content in zero or more pkt-line packets and a flush packet at the end. Finally, a second list of "key=value" pairs terminated with a flush packet is expected. The filter can change the status in the second list or keep the status as is with an empty list. Please note that the empty list must be terminated with a flush packet regardless.フィルタは、フラッシュパケットで終了する "key = value"ペアのリストで応答することが期待されています。フィルタに問題がない場合は、リストに「成功」??ステータスが含まれている必要があります。これらのパケットの直後に、フィルタは0個以上のパケットラインパケットと最後にフラッシュパケットでコンテンツを送信することが期待されています。最後に、フラッシュパケットで終了する2番目の "key = value"ペアのリストが期待されます。フィルタは、2番目のリストのステータスを変更したり、空のリストと同じステータスを維持したりできます。空のリストは関係なくフラッシュパケットで終了しなければならないことに注意してください。

packet:          git< status=success
packet:          git< 0000
packet:          git< SMUDGED_CONTENT
packet:          git< 0000
packet:          git< 0000  # empty list, keep "status=success" unchanged!

If the result content is empty then the filter is expected to respond with a "success" status and a flush packet to signal the empty content.結果のコンテンツが空の場合、フィルタは「成功」ステータスと空のコンテンツを通知するためのフラッシュパケットで応答することが期待されます。

packet:          git< status=success
packet:          git< 0000
packet:          git< 0000  # empty content!
packet:          git< 0000  # empty list, keep "status=success" unchanged!

In case the filter cannot or does not want to process the content, it is expected to respond with an "error" status.フィルタがコンテンツを処理できない、または処理したくない場合は、 "エラー"ステータスで応答することが期待されます。

packet:          git< status=error
packet:          git< 0000

If the filter experiences an error during processing, then it can send the status "error" after the content was (partially or completely) sent.フィルタの処理中にエラーが発生した場合は、コンテンツが(部分的にまたは完全に)送信された後にステータス "error"を送信できます。

packet:          git< status=success
packet:          git< 0000
packet:          git< HALF_WRITTEN_ERRONEOUS_CONTENT
packet:          git< 0000
packet:          git< status=error
packet:          git< 0000

In case the filter cannot or does not want to process the content as well as any future content for the lifetime of the Git process, then it is expected to respond with an "abort" status at any point in the protocol.Gitプロセスの存続期間中、フィルタがコンテンツおよび将来のコンテンツを処理できない、または処理したくない場合は、プロトコルのどの時点でも "abort"ステータスで応答することが期待されます。

packet:          git< status=abort
packet:          git< 0000

Git neither stops nor restarts the filter process in case the "error"/"abort" status is set. However, Git sets its exit code according to the filter.<driver>.required flag, mimicking the behavior of the filter.<driver>.clean / filter.<driver>.smudge mechanism."error" / "abort"ステータスが設定されている場合、Gitはフィルタ処理を停止も再開もしません。しかし、Git filter.<driver>.requiredfilter.<driver>.clean/ filter.<driver>.smudge機構の振る舞いをまねて、フラグに従って終了コードを設定します。

If the filter dies during the communication or does not adhere to the protocol then Git will stop the filter process and restart it with the next file that needs to be processed. Depending on the filter.<driver>.required flag Git will interpret that as error.通信中にフィルタが死んだりプロトコルに従わなかったりした場合、Gitはフィルタ処理を停止し、処理が必要な次のファイルでそれを再開します。filter.<driver>.requiredフラグによってはGitはそれをエラーとして解釈します。

Delayディレイ

If the filter supports the "delay" capability, then Git can send the flag "can-delay" after the filter command and pathname. This flag denotes that the filter can delay filtering the current blob (e.g. to compensate network latencies) by responding with no content but with the status "delayed" and a flush packet.フィルタが "遅延"機能をサポートしている場合、Gitはフィルタコマンドとパス名の後に "can-delay"フラグを送ることができます。このフラグは、コンテンツがなく、ステータスが "delayed"でフラッシュパケットが応答することで、フィルタが現在のBLOBのフィルタリングを遅らせることができることを示します(たとえば、ネットワークの待ち時間を補正するため)。

packet:          git> command=smudge
packet:          git> pathname=path/testfile.dat
packet:          git> can-delay=1
packet:          git> 0000
packet:          git> CONTENT
packet:          git> 0000
packet:          git< status=delayed
packet:          git< 0000

If the filter supports the "delay" capability then it must support the "list_available_blobs" command. If Git sends this command, then the filter is expected to return a list of pathnames representing blobs that have been delayed earlier and are now available. The list must be terminated with a flush packet followed by a "success" status that is also terminated with a flush packet. If no blobs for the delayed paths are available, yet, then the filter is expected to block the response until at least one blob becomes available. The filter can tell Git that it has no more delayed blobs by sending an empty list. As soon as the filter responds with an empty list, Git stops asking. All blobs that Git has not received at this point are considered missing and will result in an error.フィルタが「遅延」機能をサポートしている場合は、「list_available_blobs」コマンドをサポートしている必要があります。Gitがこのコマンドを送信した場合、フィルタは、先に遅れて現在使用可能になっているBLOBを表すパス名のリストを返すことが期待されます。リストは、フラッシュパケットで終了し、その後に「成功」??ステータスが続き、これもフラッシュパケットで終了します。利用可能な遅延経路用のブロブがまだない場合、フィルタは、少なくとも1つのブロブが利用可能になるまで応答をブロックすると予想される。フィルタは、空のリストを送信することによって、Gitに遅延BLOBがないことを通知します。フィルタが空のリストで応答するとすぐに、Gitは要求をやめます。この時点でGitが受け取っていないBLOBはすべて欠落していると見なされ、エラーになります。

packet:          git> command=list_available_blobs
packet:          git> 0000
packet:          git< pathname=path/testfile.dat
packet:          git< pathname=path/otherfile.dat
packet:          git< 0000
packet:          git< status=success
packet:          git< 0000

After Git received the pathnames, it will request the corresponding blobs again. These requests contain a pathname and an empty content section. The filter is expected to respond with the smudged content in the usual way as explained above.Gitがパス名を受け取った後、それは対応するBLOBを再び要求します。これらの要求には、パス名と空のコンテンツセクションが含まれています。フィルタは、上で説明したように、汚れたコンテンツで通常の方法で応答することが期待されています。

packet:          git> command=smudge
packet:          git> pathname=path/testfile.dat
packet:          git> 0000
packet:          git> 0000  # empty content!
packet:          git< status=success
packet:          git< 0000
packet:          git< SMUDGED_CONTENT
packet:          git< 0000
packet:          git< 0000  # empty list, keep "status=success" unchanged!
Example

A long running filter demo implementation can be found in contrib/long-running-filter/example.pl located in the Git core repository. If you develop your own long running filter process then the GIT_TRACE_PACKET environment variables can be very helpful for debugging (see git[1]).contrib/long-running-filter/example.plGitコアレポジトリには、長期にわたるフィルタデモの実装があります。あなた自身の長期実行フィルタプロセスを開発するならば、GIT_TRACE_PACKET環境変数はデバッグのために非常に役に立つことができます(git [1]を見てください)。

Please note that you cannot use an existing filter.<driver>.clean or filter.<driver>.smudge command with filter.<driver>.process because the former two use a different inter process communication protocol than the latter one.前の2つは後者とは異なるプロセス間通信プロトコルを使用するため、既存のfilter.<driver>.cleanor filter.<driver>.smudgeコマンドを使用することはできませんfilter.<driver>.process

Interaction between checkin/checkout attributesチェックイン/チェックアウト属性間の相互作用

In the check-in codepath, the worktree file is first converted with filter driver (if specified and corresponding driver defined), then the result is processed with ident (if specified), and then finally with text (again, if specified and applicable).チェックインコードパスでは、ワークツリーファイルは最初にfilterdriver(指定されている場合および対応するドライバが定義されている場合)で変換され、次にident(指定されている場合)で処理textされます。

In the check-out codepath, the blob content is first converted with text, and then ident and fed to filter.チェックアウトコードパスでは、BLOBコンテンツは最初にで変換されtext、次にidentに送られfilterます。

Merging branches with differing checkin/checkout attributes異なるチェックイン/チェックアウト属性を持つブランチのマージ

If you have added attributes to a file that cause the canonical repository format for that file to change, such as adding a clean/smudge filter or text/eol/ident attributes, merging anything where the attribute is not in place would normally cause merge conflicts.clean / smudgeフィルタやtext / eol / ident属性を追加するなど、ファイルに標準的なリポジトリ形式を変更するような属性をファイルに追加した場合、通常、属性が配置されていない場所でマージするとマージ競合が発生します。 。

To prevent these unnecessary merge conflicts, Git can be told to run a virtual check-out and check-in of all three stages of a file when resolving a three-way merge by setting the merge.renormalize configuration variable. This prevents changes caused by check-in conversion from causing spurious merge conflicts when a converted file is merged with an unconverted file.これらの不必要なマージの競合を防ぐために、Gitは、merge.renormalize構成変数を設定することによって3方向のマージを解決するときにファイルの3つのステージすべての仮想チェックアウトとチェックインを実行するように指示できます。これにより、変換されたファイルが変換されていないファイルとマージされたときに、チェックイン変換による変更によって誤ったマージの競合が発生するのを防ぎます。

As long as a "smudge→clean" results in the same output as a "clean" even on files that are already smudged, this strategy will automatically resolve all filter-related conflicts. Filters that do not act in this way may cause additional merge conflicts that must be resolved manually.すでに汚れているファイルでも「汚れ→きれい」の結果が「きれい」と同じ出力になる限り、この戦略は自動的にすべてのフィルタ関連の衝突を解決します。このように機能しないフィルタは、手動で解決しなければならない追加のマージ競合を引き起こす可能性があります。

Generating diff text差分テキストを生成する

diff

The attribute diff affects how Git generates diffs for particular files. It can tell Git whether to generate a textual patch for the path or to treat the path as a binary file. It can also affect what line is shown on the hunk header @@ -k,l +n,m @@ line, tell Git to use an external command to generate the diff, or ask Git to convert binary files to a text format before generating the diff.この属性diffは、Gitが特定のファイルに対してどのように差分を生成するかに影響します。Gitにパスのテキストパッチを生成するのか、それともバイナリファイルとして扱うのかを指示することができます。それはまた、hunk header @@ -k,l +n,m @@行に表示される行に影響を与えたり、diffを生成するために外部コマンドを使うようにGitに指示したり、diffを生成する前にGitにバイナリファイルをテキストフォーマットに変換するように依頼します。

Set セット

A path to which the diff attribute is set is treated as text, even when they contain byte values that normally never appear in text files, such as NUL.diff属性が設定されているパスは、NULのようにテキストファイルには通常現れないバイト値が含まれていても、テキストとして扱われます。

Unset 未設定

A path to which the diff attribute is unset will generate Binary files differ (or a binary patch, if binary patches are enabled).diff属性が設定されていないパスBinary files differ(またはバイナリパッチが有効な場合はバイナリパッチ)が生成されます。

Unspecified 指定なし

A path to which the diff attribute is unspecified first gets its contents inspected, and if it looks like text and is smaller than core.bigFileThreshold, it is treated as text. Otherwise it would generate Binary files differ.diff属性が指定されていないパスは、最初にその内容が検査され、それがテキストのように見え、core.bigFileThresholdより小さければ、それはテキストとして扱われます。それ以外の場合は生成されBinary files differます。

String ひも

Diff is shown using the specified diff driver. Each driver may specify one or more options, as described in the following section. The options for the diff driver "foo" are defined by the configuration variables in the "diff.foo" section of the Git config file.diffは指定されたdiffドライバを使って表示されます。次のセクションで説明するように、各ドライバは1つ以上のオプションを指定できます。差分ドライバ "foo"のオプションは、Git設定ファイルの "diff.foo"セクションにある設定変数によって定義されます。

Defining an external diff driver外部差分ドライバを定義する

The definition of a diff driver is done in gitconfig, not gitattributes file, so strictly speaking this manual page is a wrong place to talk about it. However…​diffドライバの定義はファイルでgitconfigはなくて行われるgitattributesので、厳密に言うとこのマニュアルページはそれについて話すのには間違った場所です。しかし…

To define an external diff driver jcdiff, add a section to your $GIT_DIR/config file (or $HOME/.gitconfig file) like this:外部のdiffドライバを定義するにはjcdiff$GIT_DIR/configファイル(または$HOME/.gitconfigファイル)に次のようにセクションを追加します。

[diff "jcdiff"]
	command = j-c-diff

When Git needs to show you a diff for the path with diff attribute set to jcdiff, it calls the command you specified with the above configuration, i.e. j-c-diff, with 7 parameters, just like GIT_EXTERNAL_DIFF program is called. See git[1] for details.diff属性がに設定されているパスの差分をGitが表示する必要がある場合jcdiffは、programが呼び出されるのとj-c-diff同じように、上記の設定、つまり7つのパラメータで指定したコマンドを呼び出しますGIT_EXTERNAL_DIFF。詳細はgit [1]を見てください。

Defining a custom hunk-headerカスタムハンクヘッダを定義する

Each group of changes (called a "hunk") in the textual diff output is prefixed with a line of the form:テキスト形式の差分出力における変更の各グループ(「ハンク」と呼ばれます)には、次の形式の行が先頭に付きます。

@@ -k,l +n,m @@ TEXT

This is called a hunk header. The "TEXT" portion is by default a line that begins with an alphabet, an underscore or a dollar sign; this matches what GNU diff -p output uses. This default selection however is not suited for some contents, and you can use a customized pattern to make a selection.これはハンクヘッダと呼ばれます。"TEXT"部分は、デフォルトではアルファベット、アンダースコア、ドル記号で始まる行です。これはGNU diff -pの出力が使うものと一致します。ただし、このデフォルトの選択は一部のコンテンツには適していません。カスタマイズしたパターンを使用して選択することができます。

First, in .gitattributes, you would assign the diff attribute for paths.まず、.gitattributesで、diffパスに属性を割り当てます。

*.tex	diff=tex

Then, you would define a "diff.tex.xfuncname" configuration to specify a regular expression that matches a line that you would want to appear as the hunk header "TEXT". Add a section to your $GIT_DIR/config file (or $HOME/.gitconfig file) like this:次に、「diff.tex.xfuncname」構成を定義して、ハンク・ヘッダー「TEXT」として表示したい行と一致する正規表現を指定します。このようにあなたの$GIT_DIR/configファイルにセクションを追加します$HOME/.gitconfig

[diff "tex"]
	xfuncname = "^(\\\\(sub)*section\\{.*)$"

Note. A single level of backslashes are eaten by the configuration file parser, so you would need to double the backslashes; the pattern above picks a line that begins with a backslash, and zero or more occurrences of sub followed by section followed by open brace, to the end of line.注意。単一レベルのバックスラッシュは設定ファイルパーサによって食べられるので、バックスラッシュを2倍にする必要があるでしょう。上記パターンは、バックスラッシュで始まる行を選び、そしてゼロ以上の出現がsub続くsection行の最後に、オープン括弧が続きます。

There are a few built-in patterns to make this easier, and tex is one of them, so you do not have to write the above in your configuration file (you still need to enable this with the attribute mechanism, via .gitattributes). The following built in patterns are available:これを容易にするための組み込みパターンがいくつかありますが、texそのうちの1つです。そのため、設定ファイルに上記を記述する必要はありません(属性メカニズムを使ってこれを有効にする必要があります.gitattributes)。以下の組み込みパターンが利用可能です。

  • ada suitable for source code in the Ada language.ada Ada言語のソースコードに適しています。

  • bibtex suitable for files with BibTeX coded references.bibtex BibTeXコード参照を持つファイルに適しています。

  • cpp suitable for source code in the C and C++ languages.cpp CおよびC ++言語のソースコードに適しています。

  • csharp suitable for source code in the C# language.csharp C#言語のソースコードに適しています。

  • css suitable for cascading style sheets.css カスケードスタイルシートに適しています。

  • fortran suitable for source code in the Fortran language.fortran Fortran言語のソースコードに適しています。

  • fountain suitable for Fountain documents.fountain ファウンテン文書に適しています。

  • golang suitable for source code in the Go language.golang Go言語のソースコードに適しています。

  • html suitable for HTML/XHTML documents.html HTML / XHTML文書に適しています。

  • java suitable for source code in the Java language.java Java言語のソースコードに適しています。

  • matlab suitable for source code in the MATLAB language.matlab MATLAB言語のソースコードに適しています。

  • objc suitable for source code in the Objective-C language.objc Objective-C言語のソースコードに適しています。

  • pascal suitable for source code in the Pascal/Delphi language.pascal Pascal / Delphi言語のソースコードに適しています。

  • perl suitable for source code in the Perl language.perl Perl言語のソースコードに適しています。

  • php suitable for source code in the PHP language.php PHP言語のソースコードに適しています。

  • python suitable for source code in the Python language.python Python言語のソースコードに適しています。

  • ruby suitable for source code in the Ruby language.ruby Ruby言語のソースコードに適しています。

  • tex suitable for source code for LaTeX documents.tex LaTeX文書のソースコードに適しています。

Customizing word diffword diffのカスタマイズ

You can customize the rules that git diff --word-diff uses to split words in a line, by specifying an appropriate regular expression in the "diff.*.wordRegex" configuration variable. For example, in TeX a backslash followed by a sequence of letters forms a command, but several such commands can be run together without intervening whitespace. To separate them, use a regular expression in your $GIT_DIR/config file (or $HOME/.gitconfig file) like this:git diff --word-diff"diff。*。wordRegex"構成変数に適切な正規表現を指定することで、単語を1行に分割するために使用する規則をカスタマイズできます。たとえば、TeXでは、バックスラッシュとそれに続く一連の文字がコマンドを形成しますが、そのようなコマンドのいくつかは空白を介さずに一緒に実行できます。それらを分離するには、あなたの$GIT_DIR/configファイル(あるいは$HOME/.gitconfigファイル)の中で次のような正規表現を使います。

[diff "tex"]
	wordRegex = "\\\\[a-zA-Z]+|[{}]|\\\\.|[^\\{}[:space:]]+"

A built-in pattern is provided for all languages listed in the previous section.組み込みパターンは、前のセクションにリストされているすべての言語に対して提供されています。

Performing text diffs of binary filesバイナリファイルのテキスト差分の実行

Sometimes it is desirable to see the diff of a text-converted version of some binary files. For example, a word processor document can be converted to an ASCII text representation, and the diff of the text shown. Even though this conversion loses some information, the resulting diff is useful for human viewing (but cannot be applied directly).時々それはあるバイナリファイルのテキスト変換されたバージョンのdiffを見ることが望ましいです。たとえば、ワープロ文書をASCIIテキスト表現に変換して、テキストの差分を表示することができます。この変換によって情報が失われるとしても、結果の差分は人間の目には役立ちます(ただし、直接適用することはできません)。

The textconv config option is used to define a program for performing such a conversion. The program should take a single argument, the name of a file to convert, and produce the resulting text on stdout.textconv設定オプションは、このような変換を行うためのプログラムを定義するために使用されます。プログラムは単一の引数、変換するファイルの名前を取り、結果のテキストを標準出力に出力します。

For example, to show the diff of the exif information of a file instead of the binary information (assuming you have the exif tool installed), add the following section to your $GIT_DIR/config file (or $HOME/.gitconfig file):たとえば、バイナリ情報の代わりにファイルのexif情報の差分を表示するには(exifツールがインストールされていると仮定して)、$GIT_DIR/configファイル(または$HOME/.gitconfigファイル)に次のセクションを追加します。

[diff "jpg"]
	textconv = exif
Note The text conversion is generally a one-way conversion; in this example, we lose the actual image contents and focus just on the text data. This means that diffs generated by textconv are not suitable for applying. For this reason, only git diff and the git log family of commands (i.e., log, whatchanged, show) will perform text conversion. git format-patch will never generate this output. If you want to send somebody a text-converted diff of a binary file (e.g., because it quickly conveys the changes you have made), you should generate it separately and send it as a comment in addition to the usual binary diff that you might send. テキスト変換は一般に一方向の変換です。この例では、実際の画像の内容を失い、テキストデータだけに注目します。つまり、textconvによって生成されたdiffは適用に適していません。このような理由から、のみgit diffgit logコマンドの家族(すなわち、whatchanged、ログインし、ショーは)テキスト変換を行います。git format-patchこの出力は生成されません。あなたが(それはすぐにあなたが行った変更を伝えるために、例えば)誰かのバイナリファイルのテキスト変換差分を送信したい場合は、別途、それを生成し、コメントとして、それを送信しなければならないことに加えて、通常にバイナリdiff形式つまりあなたがかもしれません送信します。

Because text conversion can be slow, especially when doing a large number of them with git log -p, Git provides a mechanism to cache the output and use it in future diffs. To enable caching, set the "cachetextconv" variable in your diff driver’s config. For example:テキストの変換は遅くなる可能性があるので、特に多数のテキストを変換する場合git log -p、Gitは出力をキャッシュして将来のdiffでそれを使用するためのメカニズムを提供します。キャッシュを有効にするには、diffドライバの設定で "cachetextconv"変数を設定してください。例えば:

[diff "jpg"]
	textconv = exif
	cachetextconv = true

This will cache the result of running "exif" on each blob indefinitely. If you change the textconv config variable for a diff driver, Git will automatically invalidate the cache entries and re-run the textconv filter. If you want to invalidate the cache manually (e.g., because your version of "exif" was updated and now produces better output), you can remove the cache manually with git update-ref -d refs/notes/textconv/jpg (where "jpg" is the name of the diff driver, as in the example above).これにより、各BLOBに対して "exif"を実行した結果が無期限にキャッシュされます。diffドライバのtextconv設定変数を変更すると、Gitは自動的にキャッシュエントリを無効にしてtextconvフィルタを再実行します。手動でキャッシュを無効にしたい場合(例えば、 "exif"のバージョンが更新され、より良い出力が得られるなど)、手動でキャッシュを削除することができますgit update-ref -d refs/notes/textconv/jpg(ここで、 "jpg"はdiffドライバの名前です)。上記の例)

Choosing textconv versus external difftextconvと外部diffの選択

If you want to show differences between binary or specially-formatted blobs in your repository, you can choose to use either an external diff command, or to use textconv to convert them to a diff-able text format. Which method you choose depends on your exact situation.リポジトリ内のバイナリBLOBと特別にフォーマットされたBLOBの違いを表示したい場合は、外部のdiffコマンドを使用するか、textconvを使用してそれらをdiff対応のテキスト形式に変換するかを選択できます。どちらの方法を選択するかは、実際の状況によって異なります。

The advantage of using an external diff command is flexibility. You are not bound to find line-oriented changes, nor is it necessary for the output to resemble unified diff. You are free to locate and report changes in the most appropriate way for your data format.外部のdiffコマンドを使用する利点は柔軟性です。行単位の変更を見つけることに縛られることはなく、また出力がunified diffのようになる必要もありません。データフォーマットに最も適した方法で変更を見つけて報告することは自由です。

A textconv, by comparison, is much more limiting. You provide a transformation of the data into a line-oriented text format, and Git uses its regular diff tools to generate the output. There are several advantages to choosing this method:それに対して、textconvははるかに制限的です。データを行指向のテキスト形式に変換すると、Gitは通常の差分ツールを使用して出力を生成します。この方法を選択することにはいくつかの利点があります。

  1. Ease of use. It is often much simpler to write a binary to text transformation than it is to perform your own diff. In many cases, existing programs can be used as textconv filters (e.g., exif, odt2txt).使いやすさ。バイナリからテキストへの変換は、独自の差分を実行するよりもはるかに簡単です。多くの場合、既存のプログラムをtextconvフィルタとして使用することができます(例:exif、odt2txt)。

  2. Git diff features. By performing only the transformation step yourself, you can still utilize many of Git’s diff features, including colorization, word-diff, and combined diffs for merges.差分機能をGitします。変換ステップのみを自分で実行することで、色付け、word-diff、結合されたdiffなど、Gitのdiff機能の多くを利用することができます。

  3. Caching. Textconv caching can speed up repeated diffs, such as those you might trigger by running git log -p.キャッシング。Textconvのキャッシングは、走らせることで誘発するような、繰り返される差分をスピードアップすることができますgit log -p

Marking files as binaryファイルをバイナリとしてマークする

Git usually guesses correctly whether a blob contains text or binary data by examining the beginning of the contents. However, sometimes you may want to override its decision, either because a blob contains binary data later in the file, or because the content, while technically composed of text characters, is opaque to a human reader. For example, many postscript files contain only ASCII characters, but produce noisy and meaningless diffs.Gitは通常、コンテンツの先頭を調べることによって、BLOBにテキストデータとバイナリデータのどちらが含まれているかを正しく推測します。ただし、BLOBのバイナリデータがファイルの後半に含まれているため、あるいは技術的にはテキスト文字で構成されているにもかかわらず、その内容が読者に不透明であるために、決定を上書きしたい場合があります。たとえば、多くのPostScriptファイルにはASCII文字しか含まれていませんが、ノイズがあり意味のない差分が生成されます。

The simplest way to mark a file as binary is to unset the diff attribute in the .gitattributes file:ファイルをバイナリとしてマークする最も簡単な方法は、.gitattributesファイル内のdiff属性を設定解除することです。

*.ps -diff

This will cause Git to generate Binary files differ (or a binary patch, if binary patches are enabled) instead of a regular diff.これにより、Git Binary files differは通常の差分の代わりに(またはバイナリパッチが有効な場合はバイナリパッチを)生成します。

However, one may also want to specify other diff driver attributes. For example, you might want to use textconv to convert postscript files to an ASCII representation for human viewing, but otherwise treat them as binary files. You cannot specify both -diff and diff=ps attributes. The solution is to use the diff.*.binary config option:しかし、他のdiffドライバの属性も指定したいと思うかもしれません。たとえば、textconvPostScriptファイルを人間が見るためのASCII表現に変換したいが、それ以外の場合はバイナリファイルとして扱うことをお勧めします。-diffdiff=ps属性の両方を指定することはできません。解決策はdiff.*.binaryconfigオプションを使うことです:

[diff "ps"]
  textconv = ps2ascii
  binary = true

Performing a three-way merge3者間マージを実行する

merge

The attribute merge affects how three versions of a file are merged when a file-level merge is necessary during git merge, and other commands such as git revert and git cherry-pick.属性は、mergeファイルレベルのマージが中に必要な場合に、ファイルの三つのバージョンがマージされる方法に影響を与えるgit merge、とのような他のコマンドgit revertgit cherry-pick

Set セット

Built-in 3-way merge driver is used to merge the contents in a way similar to merge command of RCS suite. This is suitable for ordinary text files.組み込みの3-wayマージドライバは、suiteのmergeコマンドと同様の方法で内容をマージするために使用されRCSます。これは通常のテキストファイルに適しています。

Unset 未設定

Take the version from the current branch as the tentative merge result, and declare that the merge has conflicts. This is suitable for binary files that do not have a well-defined merge semantics.現在のブランチのバージョンを暫定的なマージ結果として取得し、マージに競合があることを宣言します。これは、明確に定義されたマージセマンティクスを持たないバイナリファイルに適しています。

Unspecified 指定なし

By default, this uses the same built-in 3-way merge driver as is the case when the merge attribute is set. However, the merge.default configuration variable can name different merge driver to be used with paths for which the merge attribute is unspecified.デフォルトでは、これはmerge属性が設定されている場合と同じ組み込みの3ウェイマージドライバを使用します。ただし、merge.default構成変数は、merge属性が指定されていないパスで使用される別のマージドライバを指定できます。

String ひも

3-way merge is performed using the specified custom merge driver. The built-in 3-way merge driver can be explicitly specified by asking for "text" driver; the built-in "take the current branch" driver can be requested with "binary".指定したカスタムマージドライバを使用して3者間マージを実行します。組み込みの3-wayマージドライバは "text"ドライバを要求することで明示的に指定することができます。組み込みの "take the current branch"ドライバは "binary"でリクエストできます。

Built-in merge drivers組み込みマージドライバ

There are a few built-in low-level merge drivers defined that can be asked for via the merge attribute.merge属性を介して要求できる、定義済みの組み込みの低レベルのマージドライバがいくつかあります。

text テキスト

Usual 3-way file level merge for text files. Conflicted regions are marked with conflict markers <<<<<<<, ======= and >>>>>>>. The version from your branch appears before the ======= marker, and the version from the merged branch appears after the ======= marker.テキストファイル用の通常の3-wayファイルレベルのマージ。競合の領域が衝突マーカでマークされている<<<<<<<=======>>>>>>>。ブランチからのバージョンは=======マーカーの前に表示され、マージされたブランチからのバージョンは=======マーカーの後に表示されます。

binary バイナリ

Keep the version from your branch in the work tree, but leave the path in the conflicted state for the user to sort out.作業ツリー内のブランチからのバージョンを保持しますが、ユーザーが整理するためにパスを競合状態のままにします。

union 連合

Run 3-way file level merge for text files, but take lines from both versions, instead of leaving conflict markers. This tends to leave the added lines in the resulting file in random order and the user should verify the result. Do not use this if you do not understand the implications.テキストファイルに対して3方向のファイルレベルマージを実行しますが、競合マーカーを残さずに両方のバージョンから行を取得します。これは結果のファイルに追加された行をランダムな順序で残す傾向があり、ユーザーは結果を確認する必要があります。意味がわからない場合は使用しないでください。

Defining a custom merge driverカスタムマージドライバを定義する

The definition of a merge driver is done in the .git/config file, not in the gitattributes file, so strictly speaking this manual page is a wrong place to talk about it. However…​マージドライバの定義は.git/configファイル内ではなくファイル内で行われるgitattributesので、厳密に言うとこのマニュアルページはそれについて話すのには間違った場所です。しかし…

To define a custom merge driver filfre, add a section to your $GIT_DIR/config file (or $HOME/.gitconfig file) like this:カスタムマージドライバを定義するには、次のようにファイル(またはファイル)にfilfreセクションを追加します。$GIT_DIR/config$HOME/.gitconfig

[merge "filfre"]
	name = feel-free merge driver
	driver = filfre %O %A %B %L %P
	recursive = binary

The merge.*.name variable gives the driver a human-readable name.このmerge.*.name変数は、ドライバに人間が読める名前を付けます。

The merge.*.driver variable’s value is used to construct a command to run to merge ancestor’s version (%O), current version (%A) and the other branches' version (%B). These three tokens are replaced with the names of temporary files that hold the contents of these versions when the command line is built. Additionally, %L will be replaced with the conflict marker size (see below).merge.*.driver変数の値は、祖先のバージョン(マージするために実行するコマンドを構築するために使用される%O)、現在のバージョン(%A)および他の枝バージョンを(%B)。これら3つのトークンは、コマンドラインが構築されたときにこれらのバージョンの内容を保持する一時ファイルの名前に置き換えられます。さらに、%Lは競合マーカーのサイズに置き換えられます(下記参照)。

The merge driver is expected to leave the result of the merge in the file named with %A by overwriting it, and exit with zero status if it managed to merge them cleanly, or non-zero if there were conflicts.マージドライバは、マージの結果をwith %Aで上書きすることでwithという名前のファイルに残し、うまくマージできた場合は0のステータスで、衝突があった場合は0以外のステータスで終了します。

The merge.*.recursive variable specifies what other merge driver to use when the merge driver is called for an internal merge between common ancestors, when there are more than one. When left unspecified, the driver itself is used for both internal merge and the final merge.このmerge.*.recursive変数は、共通の祖先間の内部マージのためにマージドライバが呼び出されるときに、複数のマージドライバが使用されるときに使用する他のマージドライバを指定します。指定しない場合は、ドライバ自体が内部マージと最終マージの両方に使用されます。

The merge driver can learn the pathname in which the merged result will be stored via placeholder %P.マージドライバは、マージ結果がプレースホルダを介して格納されるパス名を知ることができます%P

conflict-marker-size

This attribute controls the length of conflict markers left in the work tree file during a conflicted merge. Only setting to the value to a positive integer has any meaningful effect.この属性は、競合マージ中に作業ツリーファイルに残される競合マーカーの長さを制御します。値を正の整数に設定するだけで、意味のある効果が得られます。

For example, this line in .gitattributes can be used to tell the merge machinery to leave much longer (instead of the usual 7-character-long) conflict markers when merging the file Documentation/git-merge.txt results in a conflict.たとえば、この行を.gitattributes使用すると、ファイルDocumentation/git-merge.txtをマージすると競合が発生したときに、(通常の7文字の長さではなく)はるかに長い競合マーカーを残すようにマージ機構に指示できます。

Documentation/git-merge.txt	conflict-marker-size=32

Checking whitespace errors空白エラーのチェック

whitespace

The core.whitespace configuration variable allows you to define what diff and apply should consider whitespace errors for all paths in the project (See git-config[1]). This attribute gives you finer control per path.core.whitespaceコンフィギュレーション変数は、あなたが何を定義することができます差分をし、適用する(参照プロジェクト内のすべてのパスのための空白の誤差を考慮しなければならないのgit-config設定を[1] )。この属性により、パスごとに細かく制御できます。

Set セット

Notice all types of potential whitespace errors known to Git. The tab width is taken from the value of the core.whitespace configuration variable.Gitに知られているすべての種類の潜在的な空白エラーに注意してください。タブ幅は、core.whitespace構成変数の値から取得されます。

Unset 未設定

Do not notice anything as error.エラーとして何も気にしないでください。

Unspecified 指定なし

Use the value of the core.whitespace configuration variable to decide what to notice as error.core.whitespace構成変数の値を使用して、何をエラーと見なすかを決めます。

String ひも

Specify a comma separate list of common whitespace problems to notice in the same format as the core.whitespace configuration variable.注意すべき一般的な空白の問題のコンマ区切りのリストを、core.whitespace構成変数と同じ形式で指定してください。

Creating an archiveアーカイブを作成する

export-ignore

Files and directories with the attribute export-ignore won’t be added to archive files.属性export-ignoreを持つファイルとディレクトリはアーカイブファイルに追加されません。

export-subst

If the attribute export-subst is set for a file then Git will expand several placeholders when adding this file to an archive. The expansion depends on the availability of a commit ID, i.e., if git-archive[1] has been given a tree instead of a commit or a tag then no replacement will be done. The placeholders are the same as those for the option --pretty=format: of git-log[1], except that they need to be wrapped like this: $Format:PLACEHOLDERS$ in the file. E.g. the string $Format:%H$ will be replaced by the commit hash.属性export-substがファイルに設定されている場合、Gitはこのファイルをアーカイブに追加するときにいくつかのプレースホルダーを拡張します。拡張はコミットIDの有効性に依存します。すなわち、もしgit-archive [1]がコミットやタグの代わりにツリーを与えられているなら、置き換えは行われません。プレースホルダには、オプションのものと同じである--pretty=format:[1]のgit-ログ:彼らはこのようにラップする必要があることを除いて、$Format:PLACEHOLDERS$ファイルインチ 例えば、文字列$Format:%H$はコミットハッシュに置き換えられます。

Packing objects梱包オブジェクト

delta

Delta compression will not be attempted for blobs for paths with the attribute delta set to false.属性deltaがfalseに設定されているパスのBLOBに対して、デルタ圧縮は試行されません。

Viewing files in GUI toolsGUIツールでファイルを表示する

encoding

The value of this attribute specifies the character encoding that should be used by GUI tools (e.g. gitk[1] and git-gui[1]) to display the contents of the relevant file. Note that due to performance considerations gitk[1] does not use this attribute unless you manually enable per-file encodings in its options.この属性の値は、関連するファイルの内容を表示するためにGUIツール(例えば、gitk [1]git-gui [1])によって使用されるべき文字エンコーディングを指定します。パフォーマンスの観点から、gitk [1]はオプションでファイルごとのエンコーディングを手動で有効にしない限りこの属性を使いません。

If this attribute is not set or has an invalid value, the value of the gui.encoding configuration variable is used instead (See git-config[1]).この属性が設定されていないか無効な値を持つ場合は、gui.encoding代わりに設定変数の値が使用されます(git-config [1]を参照)。

USING MACRO ATTRIBUTESマクロ属性の使用

You do not want any end-of-line conversions applied to, nor textual diffs produced for, any binary file you track. You would need to specify e.g.追跡しているバイナリファイルに行末変換を適用したり、テキスト形式の差分を生成したりすることは望ましくありません。あなたが指定する必要があるでしょう

*.jpg -text -diff

but that may become cumbersome, when you have many attributes. Using macro attributes, you can define an attribute that, when set, also sets or unsets a number of other attributes at the same time. The system knows a built-in macro attribute, binary:しかし、多くの属性があると、それは面倒になるかもしれません。マクロ属性を使用して、設定時に他の多数の属性も同時に設定または設定解除する属性を定義できます。システムは組み込みマクロ属性を知っていますbinary

*.jpg binary

Setting the "binary" attribute also unsets the "text" and "diff" attributes as above. Note that macro attributes can only be "Set", though setting one might have the effect of setting or unsetting other attributes or even returning other attributes to the "Unspecified" state.「binary」属性を設定すると、上記のように「text」属性と「diff」属性も設定解除されます。マクロ属性は "Set"しか設定できませんが、設定すると他の属性を設定または設定解除したり、他の属性を "Unspecified"状態に戻したりすることがあります。

DEFINING MACRO ATTRIBUTESマクロ属性の定義

Custom macro attributes can be defined only in top-level gitattributes files ($GIT_DIR/info/attributes, the .gitattributes file at the top level of the working tree, or the global or system-wide gitattributes files), not in .gitattributes files in working tree subdirectories. The built-in macro attribute "binary" is equivalent to:カスタムマクロの属性は唯一のトップレベルで定義することができ、ファイルをgitattributes( $GIT_DIR/info/attributes.gitattributes作業ツリーのトップレベルにあるファイル、またはグローバルまたはシステム全体のgitattributesファイル)ないで、.gitattributesツリーのサブディレクトリを作業中のファイル。組み込みマクロ属性 "binary"は、次のものと同等です。

[attr]binary -diff -merge -text

EXAMPLES

If you have these three gitattributes file:これら3つのgitattributesファイルがある場合

(in $GIT_DIR/info/attributes)
a*	foo !bar -baz
(in .gitattributes)
abc	foo bar baz
(in t/.gitattributes)
ab*	merge=filfre
abc	-foo -bar
*.c	frotz

the attributes given to path t/abc are computed as follows:pathに与えられた属性t/abcは次のように計算されます。

  1. By examining t/.gitattributes (which is in the same directory as the path in question), Git finds that the first line matches. merge attribute is set. It also finds that the second line matches, and attributes foo and bar are unset.調べてt/.gitattributes(問題のパスと同じディレクトリにある)、Gitは最初の行が一致することを見つけます。merge属性が設定されています。また、2行目が一致し、属性fooand barが設定されていないこともわかります。

  2. Then it examines .gitattributes (which is in the parent directory), and finds that the first line matches, but t/.gitattributes file already decided how merge, foo and bar attributes should be given to this path, so it leaves foo and bar unset. Attribute baz is set.それから.gitattributes(親ディレクトリにある)調べて、最初の行が一致することを見つけt/.gitattributesます、しかしfileはすでに方法を決定しましたmergefooそして、bar属性はこのパスに与えられるべきであるので、それは去りfooそしてbar設定解除されます。属性bazが設定されています。

  3. Finally it examines $GIT_DIR/info/attributes. This file is used to override the in-tree settings. The first line is a match, and foo is set, bar is reverted to unspecified state, and baz is unset.最後に調べます$GIT_DIR/info/attributes。このファイルはツリー内の設定を上書きするために使用されます。最初の行は一致であり、foo設定され、bar不特定の状態に戻され、そしてbaz設定解除されます。

As the result, the attributes assignment to t/abc becomes:結果として、への属性の割り当ては次のようにt/abcなります。

foo	set to true
bar	unspecified
baz	set to false
merge	set to string value "filfre"
frotz	unspecified

SEE ALSO関連項目

git-check-attr[1].gitのチェック-ATTR [1]

GIT

Part of the git[1] suite一部のgit [1]スイート

関連記事

スポンサーリンク

名古屋港水族館

ホームページ製作・web系アプリ系の製作案件募集中です。

上に戻る