Movatterモバイル変換


[0]ホーム

URL:


Git
English ▾Topics ▾ Latest version ▾git-commit last updated in 2.52.0

NAME

git-commit - Record changes to the repository

SYNOPSIS

gitcommit [-a |--interactive |--patch] [-s] [-v] [-u[<mode>]] [--amend]   [--dry-run]<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 andthe given log message describing the changes. The new commit is adirect child of HEAD, usually the tip of the current branch, and thebranch is updated to point to it (unless no branch is associated withthe working tree, in which caseHEAD is "detached" as described ingit-checkout[1]).

The content to be committed can be specified in several ways:

  1. by usinggit-add[1] to incrementally "add" changes to theindex before using thecommit command (Note: even modified filesmust be "added");

  2. by usinggit-rm[1] to remove files from the working treeand the index, again before using thecommit command;

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

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

  5. by using the--interactive or--patch switches with thecommit commandto decide one by one which files or hunks should be part of the commitin addition to contents in the index,before finalizing the operation. See the “Interactive Mode” section ofgit-add[1] to learn how to operate these modes.

The--dry-run option can be used to obtain asummary of what is included by any of the above for the nextcommit by giving the same set of parameters (options and paths).

If you make a commit and then find a mistake immediately afterthat, you can recover from it withgitreset.

OPTIONS

-a
--all

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

-p
--patch

Use the interactive patch selection interface to choosewhich changes to commit. Seegit-add[1] fordetails.

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

Generate diffs with<n> lines of context. Defaults todiff.contextor 3 if the config option is unset.

--inter-hunk-context=<n>

Show the context between diff hunks, up to the specified<number>of lines, thereby fusing hunks that are close to each other.Defaults todiff.interHunkContext or 0 if the config optionis unset.

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

Take an existing<commit> object, and reuse the log messageand 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 thatthe user can further edit the commit message.

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

Create a new commit which "fixes up"<commit> when applied withgitrebase--autosquash. Plain--fixup=<commit> creates a"fixup!" commit which changes the content of<commit> but leavesits log message untouched.--fixup=amend:<commit> is similar butcreates 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 whichreplaces the log message of<commit> with its own log messagebut makes no changes to the content of<commit>.

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

The commit created by--fixup=amend:<commit> is similar but itstitle is instead prefixed with "amend!". The log message of<commit> is copied into the log message of the "amend!" commit andopened in an editor so it can be refined. Whengitrebase--autosquash squashes the "amend!" commit into<commit>, thelog message of<commit> is replaced by the refined log messagefrom the "amend!" commit. It is an error for the "amend!" commit’slog message to be empty unless--allow-empty-message isspecified.

--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 bygitrebase--autosquash, it replaces the log message of<commit>without making any other changes.

Neither "fixup!" nor "amend!" commits change authorship of<commit> when applied bygitrebase--autosquash.Seegit-rebase[1] for details.

--squash=<commit>

Construct a commit message for use withgitrebase--autosquash.The commit message title is taken from the specifiedcommit with a prefix of "squash! ". Can be used with additionalcommit message options (-m/-c/-C/-F). Seegit-rebase[1] for details.

--reset-author

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

--short

When doing a dry-run, give the output in the short-format. Seegit-status[1] for details. Implies--dry-run.

--branch

Show the branch and tracking info even in short-format.

--porcelain

When doing a dry-run, give the output in a porcelain-readyformat. Seegit-status[1] for details. Implies--dry-run.

--long

When doing a dry-run, give the output in the long-format.Implies--dry-run.

-z
--null

When showingshort orporcelain status output, print thefilename verbatim and terminate the entries withNUL, instead ofLF.If no format is given, implies the--porcelain output format.Without the-z option, filenames with "unusual" characters arequoted as explained for the configuration variablecore.quotePath(seegit-config[1]).

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

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

--author=<author>

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

--date=<date>

Override the author date used in the commit.

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

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

The-m option is mutually exclusive with-c,-C, and-F.

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

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

-s
--signoff
--no-signoff

Add aSigned-off-by trailer by the committer at the end of the commitlog message. The meaning of a signoff depends on the projectto which you’re committing. For example, it may certify thatthe committer has the rights to submit the work under theproject’s license or agrees to some contributor representation,such as a Developer Certificate of Origin.(Seehttps://developercertificate.org for the one used by theLinux kernel and Git projects.) Consult the documentation orleadership of the project to which you’re contributing tounderstand how the signoffs are used in that project.

The--no-signoff option can be used to countermand an earlier--signoffoption on the command line.

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

Specify a (<token>,<value>) pair that should be applied as atrailer. (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 theSigned-off-by trailerand theHelped-by trailer to the commit message.)Thetrailer.* configuration variables(git-interpret-trailers[1]) can be used to define ifa duplicated trailer is omitted, where in the run of trailerseach trailer would appear, and other details.

-n
--verify
--no-verify

Bypass thepre-commit andcommit-msg hooks.See alsogithooks[5].

--allow-empty

Usually recording a commit that has the exact same tree as itssole parent commit is a mistake, and the command prevents youfrom making such a commit. This option bypasses the safety, andis primarily for use by foreign SCM interface scripts.

--allow-empty-message

Create a commit with an empty commit message without using plumbingcommands likegit-commit-tree[1]. Like--allow-empty, thiscommand is primarily for use by foreign SCM interface scripts.

--cleanup=<mode>

Determine how the supplied commit message should becleaned up before committing. The<mode> can bestrip,whitespace,verbatim,scissors ordefault.

strip

Strip leading and trailing empty lines, trailing whitespace,commentary and collapse consecutive empty lines.

whitespace

Same asstrip except #commentary is not removed.

verbatim

Do not change the message at all.

scissors

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

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

Same asstrip if the message is to be edited.Otherwisewhitespace.

The default can be changed by thecommit.cleanup configurationvariable (seegit-config[1]).

-e
--edit

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

--no-edit

Use the selected commit message without launching an editor.For example,gitcommit--amend--no-edit amends a commitwithout changing its commit message.

--amend

Replace the tip of the current branch by creating a newcommit. The recorded tree is prepared as usual (includingthe effect of the-i and-o options and explicitpathspec), and the message from the original commit is usedas the starting point, instead of an empty message, when noother message is specified from the command line via optionssuch as-m,-F,-c, etc. The new commit has the sameparents and author as the current one (the--reset-authoroption can countermand this).

It is a rough equivalent for:

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

but can be used to amend a merge commit.

You should understand the implications of rewriting history if youamend a commit that has already been published. (See the "RECOVERINGFROM UPSTREAM REBASE" section ingit-rebase[1].)

--no-post-rewrite

Bypass thepost-rewrite hook.

-i
--include

Before making a commit out of staged contents so far,stage the contents of paths given on the command lineas well. This is usually not what you want unless youare concluding a conflicted merge.

-o
--only

Make a commit by taking the updated working tree contentsof the paths specified on thecommand line, disregarding any contents that have beenstaged for other paths. This is the default mode of operation ofgitcommit 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, thenno paths need to be specified, which can be used to amendthe last commit without committing changes that havealready been staged. If used together with--allow-emptypaths 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. Pathspecelements are separated byLF orCR/LF. Pathspec elements can bequoted as explained for the configuration variablecore.quotePath(seegit-config[1]). See also--pathspec-file-nul andglobal--literal-pathspecs.

--pathspec-file-nul

Only meaningful with--pathspec-from-file. Pathspec elements areseparated withNUL character and all other characters are takenliterally (including newlines and quotes).

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

Show untracked files.

The<mode> parameter is optional (defaults toall), and is used tospecify the handling of untracked files; when-u is not used, thedefault isnormal, i.e. show untracked files and directories.

The possible options are:

no

Show no untracked files

normal

Shows untracked files and directories

all

Also shows individual files in untracked directories.

All usual spellings for Boolean valuetrue are taken asnormalandfalse asno.The default can be changed using thestatus.showUntrackedFilesconfiguration variable documented ingit-config[1].

-v
--verbose

Show unified diff between theHEAD commit and whatwould be committed at the bottom of the commit messagetemplate to help the user describe the commit by remindingwhat changes the commit has.Note that this diff output doesn’t have itslines prefixed with#. This diff will not be a partof the commit message. See thecommit.verbose configurationvariable ingit-config[1].

If specified twice, show in addition the unified diff betweenwhat would be committed and the worktree files, i.e. the unstagedchanges to tracked files.

-q
--quiet

Suppress commit summary message.

--dry-run

Do not create a commit, but show a list of paths that areto be committed, paths with local changes that will be leftuncommitted and paths that are untracked.

--status

Include the output ofgit-status[1] in the commitmessage template when using an editor to prepare the commitmessage. Defaults to on, but can be used to overrideconfiguration variablecommit.status.

--no-status

Do not include the output ofgit-status[1] in thecommit message template when using an editor to prepare thedefault commit message.

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

GPG-sign commits. The<key-id> is optional anddefaults to the committer identity; if specified, it must bestuck to the option without a space.--no-gpg-sign is useful tocountermand bothcommit.gpgSign configuration variable, andearlier--gpg-sign.

--

Do not interpret any more arguments as options.

<pathspec>...

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

For more details, see thepathspec entry ingitglossary[7].

EXAMPLES

When recording your own work, the contents of modified files inyour working tree are temporarily stored to a staging areacalled the "index" withgitadd. A file can bereverted back, only in the index but not in the working tree,to that of the last commit withgitrestore--staged<file>,which effectively revertsgitadd and prevents the changes tothis file from participating in the next commit. After buildingthe state to be committed incrementally with these commands,gitcommit (without any pathname parameter) is used to record whathas been staged so far. This is the most basic form of thecommand. An example:

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

Instead of staging files after each individual change, you cantellgitcommit to notice the changes to the files whosecontents are tracked inyour working tree and do correspondinggitadd andgitrmfor you. That is, this example does the same as the earlierexample if there is no other change in your working tree:

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

The commandgitcommit-a first looks at your working tree,notices that you have modifiedhello.c and removedgoodbye.c,and performs necessarygitadd andgitrm for you.

After staging changes to many files, you can alter the order thechanges are recorded in, by giving pathnames togitcommit.When pathnames are given, the command makes a commit thatonly records the changes made to the named paths:

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

This makes a commit that records the modification toMakefile.The changes staged forhello.c andhello.h are not includedin the resulting commit. However, their changes are not lost — they are still staged and merely held back. After the abovesequence, if you do:

$ git commit

this second commit would record the changes tohello.c andhello.h as expected.

After a merge (initiated bygitmerge orgitpull) stopsbecause of conflicts, cleanly mergedpaths are already staged to be committed for you, and paths thatconflicted are left in unmerged state. You would have to firstcheck which paths are conflicting withgitstatusand after fixing them manually in your working tree, you wouldstage the result as usual withgitadd:

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

After resolving conflicts and staging the result,gitls-files-uwould stop mentioning the conflicted path. When you are done,rungitcommit to finally record the merge:

$ git commit

As with the case to record your own changes, you can use-aoption to save typing. One difference is that during a mergeresolution, you cannot usegitcommit with pathnames toalter the order the changes are committed, because the mergeshould be recorded as a single commit. In fact, the commandrefuses to run when given pathnames (but see-i option).

COMMIT INFORMATION

Author and committer information is taken from the following environmentvariables, if set:

  • GIT_AUTHOR_NAME

  • GIT_AUTHOR_EMAIL

  • GIT_AUTHOR_DATE

  • GIT_COMMITTER_NAME

  • GIT_COMMITTER_EMAIL

  • GIT_COMMITTER_DATE

(nb "<", ">" and "\n"s are stripped)

The author and committer names are by convention some form of a personal name(that is, the name by which other humans refer to you), although Git does notenforce or require any particular form. Arbitrary Unicode may be used, subjectto the constraints listed above. This name has no effect on authentication; forthat, see thecredential.username variable ingit-config[1].

In case (some of) these environment variables are not set, the informationis taken from the configuration itemsuser.name anduser.email, or, if notpresent, the environment variableEMAIL, or, if that is not set,system user name and the hostname used for outgoing mail (takenfrom/etc/mailname and falling back to the fully qualified hostname whenthat file does not exist).

Theauthor.name andcommitter.name and their corresponding email optionsoverrideuser.name anduser.email if set and are overridden themselves bythe environment variables.

The typical usage is to set just theuser.name anduser.email variables;the other options are provided for more complex use cases.

DATE FORMATS

TheGIT_AUTHOR_DATE andGIT_COMMITTER_DATE environment variablessupport the following date formats:

Git internal format

It is<unix-timestamp><time-zone-offset>, where<unix-timestamp> is the number of seconds since the UNIX epoch.<time-zone-offset> is a positive or negative offset from UTC.For example CET (which is 1 hour ahead of UTC) is+0100.

RFC 2822

The standard date format as described by RFC 2822, for exampleThu,07Apr200522:13:13+0200.

ISO 8601

Time and date specified by the ISO 8601 standard, for example2005-04-07T22:13:13. The parser accepts a space instead of theT character as well. Fractional parts of a second will be ignored,for example2005-04-07T22:13:13.019 will be treated as2005-04-07T22:13:13.

Note
In addition, the date part is accepted in the following formats:YYYY.MM.DD,MM/DD/YYYY andDD.MM.YYYY.

In addition to recognizing all date formats above, the--date optionwill also try to make sense of other, more human-centric date formats,such as relative dates like "yesterday" or "last Friday at noon".

DISCUSSION

Though not required, it’s a good idea to begin the commit messagewith a single short (no more than 50 characters) line summarizing thechange, followed by a blank line and then a more thorough description.The text up to the first blank line in a commit message is treatedas the commit title, and that title is used throughout Git.For example,git-format-patch[1] turns a commit into email, and it usesthe title on the Subject line and the rest of the commit in the body.

Git is to some extent character encoding agnostic.

  • The contents of the blob objects are uninterpreted sequencesof bytes. There is no encoding translation at the corelevel.

  • Path names are encoded in UTF-8 normalization form C. Thisapplies to tree objects, the index file, ref names, as well aspath names in command line arguments, environment variablesand config files (.git/config (seegit-config[1]),gitignore[5],gitattributes[5] andgitmodules[5]).

    Note that Git at the core level treats path names simply assequences of non-NUL bytes, there are no path name encodingconversions (except on Mac and Windows). Therefore, usingnon-ASCII path names will mostly work even on platforms and filesystems that use legacy extended ASCII encodings. However,repositories created on such systems will not work properly onUTF-8-based systems (e.g. Linux, Mac, Windows) and vice versa.Additionally, many Git-based tools simply assume path names tobe UTF-8 and will fail to display other encodings correctly.

  • Commit log messages are typically encoded in UTF-8, but otherextended ASCII encodings are also supported. This includesISO-8859-x, CP125x and many others, butnot UTF-16/32,EBCDIC and CJK multi-byte encodings (GBK, Shift-JIS, Big5,EUC-x, CP9xx etc.).

Although we encourage that the commit log messages are encodedin UTF-8, both the core and Git Porcelain are designed not toforce UTF-8 on projects. If all participants of a particularproject find it more convenient to use legacy encodings, Gitdoes not forbid it. However, there are a few things to keep inmind.

  1. gitcommit andgitcommit-tree issuea warning if the commit log message given to it does not looklike a valid UTF-8 string, unless you explicitly say yourproject uses a legacy encoding. The way to say this is tohavei18n.commitEncoding in.git/config file, like this:

    [i18n]commitEncoding = ISO-8859-1

    Commit objects created with the above setting record the valueofi18n.commitEncoding in theirencoding header. This is tohelp other people who look at them later. Lack of this headerimplies that the commit log message is encoded in UTF-8.

  2. gitlog,gitshow,gitblame and friends look at theencoding header of a commit object, and try to re-code thelog message into UTF-8 unless otherwise specified. You canspecify the desired output encoding withi18n.logOutputEncoding in.git/config file, like this:

    [i18n]logOutputEncoding = ISO-8859-1

    If you do not have this configuration variable, the value ofi18n.commitEncoding is used instead.

Note that we deliberately chose not to re-code the commit logmessage when a commit is made to force UTF-8 at the commitobject level, because re-coding to UTF-8 is not necessarily areversible operation.

ENVIRONMENT AND CONFIGURATION VARIABLES

The editor used to edit the commit log message will be chosen from theGIT_EDITOR environment variable, thecore.editor configuration variable, theVISUAL environment variable, or theEDITOR environment variable (in thatorder). Seegit-var[1] for details.

Everything above this line in this section isn’t included from thegit-config[1] documentation. The content that follows is thesame as what’s found there:

commit.cleanup

This setting overrides the default of the--cleanup option ingitcommit. Changing the default can be usefulwhen you always want to keep lines that beginwith the comment character (core.commentChar, default#)in your log message, in which case youwould dogitconfigcommit.cleanupwhitespace (note that you willhave to remove the help lines that begin with the comment characterin the commit log template yourself, if you do this).

commit.gpgSign

A boolean to specify whether all commits should be GPG signed.Use of this option when doing operations such as rebase canresult in a large number of commits being signed. It may beconvenient to use an agent to avoid typing your GPG passphraseseveral times.

commit.status

A boolean to enable/disable inclusion of status information in thecommit message template when using an editor to prepare the commitmessage. Defaults totrue.

commit.template

Specify the pathname of a file to use as the template fornew commit messages.

commit.verbose

A boolean or int to specify the level of verbosity withgitcommit.

HOOKS

This command can runcommit-msg,prepare-commit-msg,pre-commit,post-commit andpost-rewrite hooks. Seegithooks[5] for moreinformation.

FILES

$GIT_DIR/COMMIT_EDITMSG

This file contains the commit message of a commit in progress.Ifgitcommit exits due to an error before creating a commit,any commit message that has been provided by the user (e.g., inan editor session) will be available in this file, but will beoverwritten by the next invocation ofgitcommit.

SEE ALSO

GIT

Part of thegit[1] suite


[8]ページ先頭

©2009-2025 Movatter.jp