SYNOPSIS

git commit [-a | --interactive | --patch] [-s] [-v] [-u[<mode>]] [--amend]
         [--dry-run] [(-c | -C | --squash) <commit> | --fixup [(amend|reword):]<commit>]
         [-F <file> | -m <msg>] [--reset-author] [--allow-empty]
         [--allow-empty-message] [--no-verify] [-e] [--author=<author>]
         [--date=<date>] [--cleanup=<mode>] [--[no-]status]
         [-i | -o] [--pathspec-from-file=<file> [--pathspec-file-nul]]
         [(--trailer <token>[(=|:)<value>])...] [-S[<keyid>]]
         [--] [<pathspec>...]

DESCRIPTION

Create a new commit containing the current contents of the index and the given log message describing the changes. The new commit is a direct child of HEAD, usually the tip of the current branch, and the branch is updated to point to it (unless no branch is associated with the working tree, in which case HEAD is "detached" as described in git-checkout(1)).

コミットするコンテンツは、いくつかの方法で指定できます:

  1. by using git-add(1) to incrementally "add" changes to the index before using the commit command (Note: even modified files must be "added");

  2. by using git-rm(1) to remove files from the working tree and the index, again before using the commit command;

  3. by listing files as arguments to the commit command (without --interactive or --patch switch), in which case the commit will ignore changes staged in the index, and instead record the current content of the listed files (which must already be known to Git);

  4. by using the -a switch with the commit command to automatically "add" changes from all known files (i.e. all files that are already listed in the index) and to automatically "rm" files in the index that have been removed from the working tree, and then perform the actual commit;

  5. by using the --interactive or --patch switches with the commit command to decide one by one which files or hunks should be part of the commit in addition to contents in the index, before finalizing the operation. See the “Interactive Mode” section of git-add(1) to learn how to operate these modes.

--dry-run オプションは、同じパラメーターのセット(オプションとパス)を指定することにより、次のコミットにて上記のいずれかに含まれるものの要約を取得するために使用できます。

If you make a commit and then find a mistake immediately after that, you can recover from it with git reset.

OPTIONS

-a
--all

Automatically stage files that have been modified and deleted, but new files you have not told Git about are not affected.

-p
--patch

対話的なパッチ選択インターフェイスを使用して、コミットする変更を選択します。 詳細については、git-add(1) を参照してください。

-U<n>
--unified=<n>

コンテキストの「<n>行」の diff を生成します。 デフォルトは diff.context 、 または構成オプションが設定されていない場合は 3 です。

--inter-hunk-context=<n>

指定の「<number>行」までの diff ハンク間のコンテキストを表示し、 それによって互いに近いハンクを融合します。 デフォルトは diff.interHunkContext 、 または構成オプションが設定されていない場合は 0 です。

-C <commit>
--reuse-message=<commit>

Take an existing <commit> object, and reuse the log message and the authorship information (including the timestamp) when creating the commit.

-c <commit>
--reedit-message=<commit>

Like -C, but with -c the editor is invoked, so that the user can further edit the commit message.

--fixup=[(amend|reword):]<commit>

Create a new commit which "fixes up" <commit> when applied with git rebase --autosquash. Plain --fixup=<commit> creates a "fixup!" commit which changes the content of <commit> but leaves its log message untouched. --fixup=amend:<commit> is similar but creates an "amend!" commit which also replaces the log message of <commit> with the log message of the "amend!" commit. --fixup=reword:<commit> creates an "amend!" commit which replaces the log message of <commit> with its own log message but makes no changes to the content of <commit>.

The commit created by plain --fixup=<commit> has a title composed of "fixup!" followed by the title of <commit>, and is recognized specially by git rebase --autosquash. The -m option may be used to supplement the log message of the created commit, but the additional commentary will be thrown away once the "fixup!" commit is squashed into <commit> by git rebase --autosquash.

The commit created by --fixup=amend:<commit> is similar but its title is instead prefixed with "amend!". The log message of <commit> is copied into the log message of the "amend!" commit and opened in an editor so it can be refined. When git rebase --autosquash squashes the "amend!" commit into <commit>, the log message of <commit> is replaced by the refined log message from the "amend!" commit. It is an error for the "amend!" commit’s log message to be empty unless --allow-empty-message is specified.

--fixup=reword:<commit> is shorthand for --fixup=amend:<commit> --only. It creates an "amend!" commit with only a log message (ignoring any changes staged in the index). When squashed by git rebase --autosquash, it replaces the log message of <commit> without making any other changes.

Neither "fixup!" nor "amend!" commits change authorship of <commit> when applied by git rebase --autosquash. See git-rebase(1) for details.

--squash=<commit>

Construct a commit message for use with git rebase --autosquash. The commit message title is taken from the specified commit with a prefix of "squash! ". Can be used with additional commit message options (-m/-c/-C/-F). See git-rebase(1) for details.

--reset-author

When used with -C/-c/--amend options, or when committing after a conflicting cherry-pick, declare that the authorship of the resulting commit now belongs to the committer. This also renews the author timestamp.

--short

ドライランを行うときに、出力を短い形式で提供します。 詳細については、 git-status(1) を参照してください。 --dry-run の指定を含んでいます。

--branch

短い形式でもブランチと追跡情報を表示します。

--porcelain

ドライランを行うときに、磁器コマンド対応の形式で出力を提供します。 詳細については、 git-status(1) を参照してください。 --dry-run の指定を含んでいます。

--long

ドライランを行うときに、出力を長い形式で提供します。 --dry-run の指定を含んでいます。

-z
--null

When showing short or porcelain status output, print the filename verbatim and terminate the entries with NUL, instead of LF. If no format is given, implies the --porcelain output format. Without the -z option, filenames with "unusual" characters are quoted as explained for the configuration variable core.quotePath (see git-config(1)).

-F <file>
--file=<file>

Take the commit message from <file>. Use - to read the message from the standard input.

--author=<author>

Override the commit author. Specify an explicit author using the standard A U Thor <author@example.com> format. Otherwise <author> is assumed to be a pattern and is used to search for an existing commit by that author (i.e. git rev-list --all -i --author=<author>); the commit author is then copied from the first such commit found.

--date=<date>

コミットで使用された作者の日付を上書きします。

-m <msg>
--message=<msg>

Use <msg> as the commit message. If multiple -m options are given, their values are concatenated as separate paragraphs.

-m オプションは、 -c-C-F と相互に排他的(mutually exclusive)です。

-t <file>
--template=<file>

When editing the commit message, start the editor with the contents in <file>. The commit.template configuration variable is often used to give this option implicitly to the command. This mechanism can be used by projects that want to guide participants with some hints on what to write in the message in what order. If the user exits the editor without editing the message, the commit is aborted. This has no effect when a message is given by other means, e.g. with the -m or -F options.

-s
--signoff
--no-signoff

コミット・ログ・メッセージの最後に、 コミッターによる「Signed-off-by」トレーラーを追加します。 signoff(訳注: 一般には手紙の(末尾の)署名)の意味は、 コミットしているプロジェクトによって異なります。 たとえば、 コミッターがプロジェクトのライセンスに基づいて作品を提出する権利を持っていることを証明したり、開発者の原産地証明書などの寄稿者の代表に同意したりする場合があります(LinuxカーネルおよびGitプロジェクトで使用されるものについては、 https://developercertificate.org を参照してください)。 プロジェクトでsignoffがどのように使用されるかを理解するには、 貢献しているプロジェクトのドキュメントまたはリーダーシップ(leadership)を参照してください。

コマンドラインで --no-signoff オプションを使用すると、 それ以前の --signoff オプションを無効にすることができます。

--trailer <token>[(=|:)<value>]

Specify a (<token>, <value>) pair that should be applied as a trailer. (e.g. git commit --trailer "Signed-off-by:C O Mitter \ <committer@example.com>" --trailer "Helped-by:C O Mitter \ <committer@example.com>" will add the Signed-off-by trailer and the Helped-by trailer to the commit message.) The trailer.* configuration variables (git-interpret-trailers(1)) can be used to define if a duplicated trailer is omitted, where in the run of trailers each trailer would appear, and other details.

-n
--verify
--no-verify

Bypass the pre-commit and commit-msg hooks. See also githooks(5).

--allow-empty

通常、唯一の親コミットとまったく同じツリーを持つコミットを記録することは間違いであり、コマンドはそのようなコミットを行うことを防ぎます。 このオプションはその安全装置をバイパスします。主に外部SCMインターフェイススクリプトで使用するためのものです。

--allow-empty-message

Create a commit with an empty commit message without using plumbing commands like git-commit-tree(1). Like --allow-empty, this command is primarily for use by foreign SCM interface scripts.

--cleanup=<mode>

Determine how the supplied commit message should be cleaned up before committing. The <mode> can be strip, whitespace, verbatim, scissors or default.

strip

先頭と末尾の空行の削除と、行末の空白を削除と、コメントの削除を行い、連続する空行を折りたたみます。

whitespace

#コメント が削除されないことを除いて、strip と同一です。

verbatim

メッセージは一切変更しません。

scissors

Same as whitespace except that everything from (and including) the line found below is truncated, if the message is to be edited. "#" can be customized with core.commentChar.

# ------------------------ >8 ------------------------
default

メッセージを編集する場合は strip と同一です。 それ以外の場合は whitespace と同一です。

デフォルトは、 commit.cleanup 構成変数によって変更できます(git-config(1) 参照)。

-e
--edit

Let the user further edit the message taken from <file> with -F <file>, command line with -m <message>, and from <commit> with -C <commit>.

--no-edit

エディターを起動せずに、選択したコミットメッセージを使用します。 たとえば、 git commit --amend --no-edit は、コミットメッセージを変更せずにコミットを修正します。

--amend

新しいコミットを作成して、現在のブランチの先端を置き換えます。 記録されたツリーは通常どおりに準備され(-i および -o オプションと明示的なパススペックの効果を含む)、空のメッセージではなく、元のコミットからのメッセージが開始点として使用されます。 他のメッセージは、コマンドラインから -m, -F, -c などのオプションを介して指定します。 新しいコミットには、現在のものと同じ親と作者があります(--reset-author オプションはこれを打ち消すことができます)。

これは、以下とおおむね同じです:

        $ git reset --soft HEAD^
        $ ... do something else to come up with the right tree ...
        $ git commit -c ORIG_HEAD

ただし、マージコミットを修正(amend)するために使用できます。

すでに公開されているコミットを修正する場合、あなたは履歴の書き換えの影響を理解する必要があります。 (git-rebase(1) の「RECOVERING FROM UPSTREAM REBASE」セクションを参照してください。)

--no-post-rewrite

Bypass the post-rewrite hook.

-i
--include

これまでにステージングされたコンテンツからコミットを行う前に、コマンドラインで指定されたパスのコンテンツもステージングします。 あなたが競合するマージを終了させるのでない限り、これは通常、あなたが希望することはないでしょう。

-o
--only

Make a commit by taking the updated working tree contents of the paths specified on the command line, disregarding any contents that have been staged for other paths. This is the default mode of operation of git commit if any paths are given on the command line, in which case this option can be omitted. If this option is specified together with --amend, then no paths need to be specified, which can be used to amend the last commit without committing changes that have already been staged. If used together with --allow-empty paths are also not required, and an empty commit will be created.

--pathspec-from-file=<file>

Pass pathspec in <file> instead of commandline args. If <file> is exactly - then standard input is used. Pathspec elements are separated by LF or CR/LF. Pathspec elements can be quoted as explained for the configuration variable core.quotePath (see git-config(1)). See also --pathspec-file-nul and global --literal-pathspecs.

--pathspec-file-nul

Only meaningful with --pathspec-from-file. Pathspec elements are separated with NUL character and all other characters are taken literally (including newlines and quotes).

-u[<mode>]
--untracked-files[=<mode>]

追跡されていないファイル(untracked files)を表示します。

The <mode> parameter is optional (defaults to all), and is used to specify the handling of untracked files; when -u is not used, the default is normal, i.e. show untracked files and directories.

可能なオプションは以下のとおりです:

no

Show no untracked files

normal

Shows untracked files and directories

all

Also shows individual files in untracked directories.

All usual spellings for Boolean value true are taken as normal and false as no. The default can be changed using the status.showUntrackedFiles configuration variable documented in git-config(1).

-v
--verbose

Show unified diff between the HEAD commit and what would be committed at the bottom of the commit message template to help the user describe the commit by reminding what changes the commit has. Note that this diff output doesn’t have its lines prefixed with #. This diff will not be a part of the commit message. See the commit.verbose configuration variable in git-config(1).

2回指定した場合は、コミットされるものとワークツリーファイルの間のunified diff、 つまり、追跡されたファイルへのステージングされていない変更を追加で表示します。

-q
--quiet

コミット要約メッセージを抑制します。

--dry-run

コミットを作成しません。ただし、コミットされるパス、コミットされないままになるローカル変更のあるパス、および追跡されないパスのリストを表示します。

--status

Include the output of git-status(1) in the commit message template when using an editor to prepare the commit message. Defaults to on, but can be used to override configuration variable commit.status.

--no-status

エディターを使用してデフォルトのコミットメッセージを準備する場合は、 git-status(1) の出力をコミットメッセージテンプレートに含めません。

-S[<key-id>]
--gpg-sign[=<key-id>]
--no-gpg-sign

GPG-sign commits. The <key-id> is optional and defaults to the committer identity; if specified, it must be stuck to the option without a space. --no-gpg-sign is useful to countermand both commit.gpgSign configuration variable, and earlier --gpg-sign.

--

これ以降の引数をオプションとして解釈しないでください。

<pathspec>...

When <pathspec> is given on the command line, commit the contents of the files that match the pathspec without recording the changes already added to the index. The contents of these files are also staged for the next commit on top of what have been staged before.

詳細については、 gitglossary(7)の「pathspec」エントリを参照してください。

EXAMPLES

When recording your own work, the contents of modified files in your working tree are temporarily stored to a staging area called the "index" with git add. A file can be reverted back, only in the index but not in the working tree, to that of the last commit with git restore --staged <file>, which effectively reverts git add and prevents the changes to this file from participating in the next commit. After building the state to be committed incrementally with these commands, git commit (without any pathname parameter) is used to record what has been staged so far. This is the most basic form of the command. An example:

$ edit hello.c
$ git rm goodbye.c
$ git add hello.c
$ git commit

個々の変更の後にファイルをステージングする代わりに、作業ツリーで内容が追跡されているファイルへの変更を通知し、対応する git addgit rm を実行するように`gitcommit`に指示できます。 つまり、以下の例は、作業ツリーに他の変更がない場合、上記の例と同じように機能します:

$ edit hello.c
$ rm goodbye.c
$ git commit -a

The command git commit -a first looks at your working tree, notices that you have modified hello.c and removed goodbye.c, and performs necessary git add and git rm for you.

多くのファイルに変更をステージングした後、 git commit にパス名を指定することで、変更が記録される順序を変更できます。 パス名が指定されると、コマンドは、指定されたパスに加えられた変更のみを記録するコミットを行います:

$ edit hello.c hello.h
$ git add hello.c hello.h
$ edit Makefile
$ git commit Makefile

これにより、 Makefile への変更を記録するコミットが行われます。 hello.chello.h に対してステージングされた変更は、結果のコミットには含まれません。 ただし、それらの変更は失われません。それらはいまだステージングに留まっているだけです。上記シーケンスの後、あなたが以下のようにすれば:

$ git commit

この2番目のコミットは、期待どおりに hello.chello.h への変更を記録します。

After a merge (initiated by git merge or git pull) stops because of conflicts, cleanly merged paths are already staged to be committed for you, and paths that conflicted are left in unmerged state. You would have to first check which paths are conflicting with git status and after fixing them manually in your working tree, you would stage the result as usual with git add:

$ git status | grep unmerged
unmerged: hello.c
$ edit hello.c
$ git add hello.c

競合を解決して結果をステージングした後、 git ls-files -u は競合するパスへの言及を停止します。 完了したら、 git commit を実行して、最終的にマージを記録します:

$ git commit

独自の変更を記録する場合と同様に、 -a オプションを使用して入力を保存できます。 一つ違うのは、マージの解決中にパス名を伴って git commit を使用して、変更がコミットされる順序を変更できないことです。これは、マージが単一のコミットとして記録される必要があるためです。 実際、パス名が指定されている場合、コマンドは実行を拒否します(ただし、 -i オプションも参照してください)。

COMMIT INFORMATION

作者とコミッターの情報は、以下の環境変数から取得されます(設定されてる場合):

  • GIT_AUTHOR_NAME

  • GIT_AUTHOR_EMAIL

  • GIT_AUTHOR_DATE

  • GIT_COMMITTER_NAME

  • GIT_COMMITTER_EMAIL

  • GIT_COMMITTER_DATE

(注: "<" と ">" と "\n" は取り除きます)

作者とコミッター名は、慣例により、個人名(つまり、他の人間があなたを参照する名前)の形式ですが、Gitは特定の形式を強制または要求しません。 上記の制約に従って、任意のUnicodeを使用できます。 この名前は認証には影響しません。認証には影響させるためには、 git-config(1)credential.username 変数を参照してください。

In case (some of) these environment variables are not set, the information is taken from the configuration items user.name and user.email, or, if not present, the environment variable EMAIL, or, if that is not set, system user name and the hostname used for outgoing mail (taken from /etc/mailname and falling back to the fully qualified hostname when that file does not exist).

author.namecommitter.name と、それらに対応する電子メールオプションは、 設定されている場合はそれぞれ user.nameuser.email をオーバーライドし、環境変数によってオーバーライドされます。

一般的な使用法は、 user.name 変数と user.email 変数のみを設定することです。 他のオプションは、より複雑なユースケースのために提供されています。

DATE FORMATS

GIT_AUTHOR_DATEGIT_COMMITTER_DATE 環境変数は、以下の日付形式をサポートします:

Git internal format

これは <unix-timestamp> <time-zone-offset> です。 ここで <unix-timestamp> はUNIXエポックからの秒数で、 <time-zone-offset> はUTCからの正または負のオフセットです。 たとえば、CET(UTCより1時間進んでる)は +0100 です。

RFC 2822

RFC 2822で説明されている標準の日付形式。たとえば、 Thu, 07 Apr 2005 22:13:13 +0200

ISO 8601

ISO 8601規格で指定されている日時(例: 2005-04-07T22:13:13)。パーサは、 T 文字の代わりにスペースも受け入れます。秒の小数部分は無視されます。たとえば、 2005-04-07T22:13:13.0192005-04-07T22:13:13 として扱われます。

Note
日付部分は、上記に加えて、 YYYY.MM.DD または MM/DD/YYYY または DD.MM.YYYY 形式が受け入れられます。

上記のすべての日付形式を認識することに加えて、 --date オプションは、 "yesterday" や "last Friday at noon" など、より人間よりの日付形式も理解しようとします。

DISCUSSION

必須ではありませんが、変更を要約した1行の短い(50文字以下の)行でコミット・メッセージを開始し、その後に空行を続け、さらに詳細な説明を続けることをお勧めします。 コミット・メッセージの最初の空行までのテキストはコミット・タイトルとして扱われ、そのタイトルはGit全体で使用されます。 たとえば、 git-format-patch(1) はコミットを電子メールに変換し、コミット・タイトルをメール件名に使い、残りのコミット・メッセージをメール本文に使います。

Gitは、ある程度までは文字エンコードに依存しません。

  • ブロブオブジェクトの内容は、解釈されていないバイトのシーケンスです。コアレベルでのエンコーディング変換はありません。

  • パス名は UTF-8 正規化形式C(UTF-8 normalization form C)でエンコードされます。 これは、 ツリー・オブジェクトと、 インデックス・ファイルと、 参照名と、 コマンドライン引数と、環境変数と、 構成ファイル( .git/config (git-config(1) 参照)と、 gitignore(5) と、 gitattributes(5) と、 gitmodules(5)) のパス名に、 適用されます。

    コアレベルのGitは、パス名を単に非NULバイトのシーケンスとして扱い、パス名をエンコードする変換はありません(MacとWindowsを除く)。したがって、非ASCIIパス名の使用は、レガシー拡張ASCIIエンコーディングを使用するプラットフォームやファイルシステムでもほとんど機能します。ただし、そのようなシステムで作成されたリポジトリは、UTF-8ベースのシステム(Linux、Mac、Windowsなど)では正しく機能しません。その逆も同様です。さらに、多くのGitベースのツールは、パス名がUTF-8であると単純に想定しており、他のエンコーディングを正しく表示できません。

  • コミット・ログ・メッセージは通常UTF-8でエンコードされますが、他の拡張ASCIIエンコードもサポートされています。これには、ISO-8859-xやCP125xなどが含まれます。 しかし、 UTF-16/32 や EBCDIC や CJK マルチバイトエンコーディング(GBK、Shift-JIS、Big5、EUC-x、CP9xxなど)は含まれません。

我々はコミットログメッセージをUTF-8でエンコードすることをお勧めしますが、コアとGit Porcelainはどちらも、プロジェクトでUTF-8を強制しないように設計されています。特定のプロジェクトのすべての参加者がレガシーエンコーディングを使用する方が便利だと感じた場合、Gitはそれを禁止しません。 ただし、覚えておくべきことがいくつかあります。

  1. git commitgit commit-tree は、 渡されたコミット・ログ・メッセージが正しい UTF-8 文字列に見えない場合に警告を表示します。 ただし、 プロジェクトがレガシーなエンコーディングを使用していることを明示的に宣言している場合は、 この警告を出しません。 その方法とは、 .git/config ファイルに i18n.commitEncoding を設定することです。 たとえば以下のようにします:

    [i18n]
            commitEncoding = ISO-8859-1

    上記の設定で作成されたコミットオブジェクトは、 encoding ヘッダーに i18n.commitEncoding の値を記録します。 これは、後でそれらを見る他の人々を助けるためです。このヘッダーがないということは、コミットログメッセージがUTF-8でエンコードされていることを意味します。

  2. git loggit showgit blame とその仲間たちは、 コミット・オブジェクトの encoding ヘッダーを見て、 特に指定がない限り、 ログ・メッセージを UTF-8 に再エンコーディングしようとします。 あなたは以下のように、 .git/config ファイルの i18n.logOutputEncoding を使用して目的の出力エンコーディングを指定できます:

    [i18n]
            logOutputEncoding = ISO-8859-1

    この構成変数がない場合は、代わりに i18n.commitEncoding の値が使用されます。

注意: UTF-8への再コーディングは必ずしも可逆的な操作ではないため、我々はコミットが行われたときにコミットログメッセージを再コーディングしないことを意図的に選択したことに注意してください。

ENVIRONMENT AND CONFIGURATION VARIABLES

The editor used to edit the commit log message will be chosen from the GIT_EDITOR environment variable, the core.editor configuration variable, the VISUAL environment variable, or the EDITOR environment variable (in that order). See git-var(1) for details.

このセクションのこの行より上にあるものはすべて、 git-config(1) ドキュメントには含まれていません。 以下の内容に関しては、git-config(1) ドキュメント にあるものと同一です。

commit.cleanup

この設定は、 git commit--cleanup オプションのデフォルトを上書きします。 詳細については、 git-commit(1) を参照してください。 デフォルトを変更すると、コメント文字(core.commentChar, デフォルトは #)で始まる行をログ・メッセージに常に残しておきたい場合に役立ちます。 その場合は、 git config commit.cleanup whitespace を実行します(注意:これを行う場合は、コミット・ログ・テンプレートのコメント文字で始まるヘルプ行を自分で削除する必要があることに注意してください)。

commit.gpgSign

すべてのコミットをGPG署名する必要があるかどうかを指定するブール値。 リベースなどの操作を行うときにこのオプションを使用すると、多数のコミットが署名される可能性があります。 エージェントを使用して、GPGパスフレーズの入力を省略するようにすると便利な場合があります。

commit.status

エディターを使用してコミット・メッセージを準備するときに、 コミット・メッセージ・テンプレートにステータス情報を含めることを 有効/無効 にするブール値。 デフォルトは true です。

commit.template

新しいコミットメッセージのテンプレートとして使用するファイルのパス名を指定します。

commit.verbose

git commit でverboseレベルを指定するブール値またはint。 詳細は git-commit(1) を参照してください。

HOOKS

このコマンドは、 commit-msg フックと、 prepare-commit-msg フックと、 pre-commit フックと、 post-commit フックと、 post-rewrite フック を実行できます。 詳細については、 githooks(5) を参照してください。

FILES

$GIT_DIR/COMMIT_EDITMSG

このファイルには、進行中のコミットのコミットメッセージが含まれています。 コミットを作成する前にエラーが原因で gitc ommit が終了した場合、ユーザーによって提供されたコミットメッセージ(エディターセッションなど)は全てこのファイルに残りますが、次の git commit の呼び出しによって上書きされます。

SEE ALSO

GIT

Part of the git(1) suite