GIT基本快照命令之git-commit

名称NAME

git-commit -记录对存储库的更改

概要SYNOPSIS

git commit [-a | --interactive | --patch] [-s] [-v] [-u<mode>] [--amend]
	   [--dry-run] [(-c | -C | --fixup | --squash) <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]]
	   [-S[<keyid>]] [--] [<pathspec>…​]

描述DESCRIPTION

创建一个新的提交,其中包含索引的当前内容以及描述更改的给定日志消息。新提交是HEAD的直接子项,通常是当前分支的尖端,并且分支被更新为指向它(除非没有分支与工作树相关联,在这种情况下HEAD如git-checkout中所述被“分离”)。

可以通过多种方式指定要提交的内容:

  1. 通过在使用commit命令之前使用git-add增量“添加”对索引的更改(注意:即使已修改的文件也必须“添加”);

  2. 再次使用git-rm [1]从工作树和索引中删除文件,然后再使用commit命令;

  3. 通过列出文件作为commit命令的参数(没有--interactive或--patch开关),在这种情况下,提交将忽略索引中暂存的更改,而是记录列出文件的当前内容(Git必须已经知道);

  4. 通过使用-a开关与commit命令一起,来自动“添加”所有已知文件(即索引中已列出的所有文件)的更改,并自动“删除”已从工作树中删除的索引中的文件 ,然后执行实际的提交;

  5. 通过使用--interactive或--patch开关与commit命令一起,在完成操作之前,一 一决定除索引中的内容外,哪些文件或块应该是提交的一部分。 请参阅git-add [1]的“交互模式”部分,以了解如何操作这些模式。

--dry-run选项可以通过提供相同的参数集(选项和路径)来获取上述任何内容在下一次提交中的摘要。

如果您提交了一个提交,然后立即发现错误,则可以使用git reset从中恢复。

选项OPTIONS

-a    --all

告诉commit命令自动暂存已修改和删除的文件,但是您未告知Git的新文件不受影响

-p    --patch

使用交互式补丁选择界面选择要提交的更改。 有关详细信息,请参见git-add [1]。

-C <commit>

--reuse-message=<commit>

获取现有的提交对象,并在创建提交时重用现有提交对象的日志消息和作者信息(包括时间戳)。

-c <commit>

--reedit-message=<commit>

与-C类似,但是-c会调用编辑器,以便用户可以进一步编辑提交消息。

--fixup=<commit>

构建一个与rebase --autosquash一起使用的提交消息。 提交消息将是指定提交的主题行,其前缀为“ fixup!”。 有关详细信息,请参见git-rebase [1]。

--squash=<commit>

构建一个与rebase --autosquash一起使用的提交消息。 提交消息主题行是从具有“ squash!”前缀的指定提交中提取的。 可以与其他提交消息选项(-m/-c/-C/-F)一起使用。 有关详细信息,请参见git-rebase [1]。

--reset-author

与-C/-c/-amend选项一起使用时,或在发生冲突的Cherry-pick之后提交时,声明结果提交的作者现在属于提交者。 这也更新了作者的时间戳。

--short

当进行dry-run时,以短格式short-format给出输出。 有关详细信息,请参见git-status [1]。Implies --dry-run

--branch

即使以短格式显示分支和跟踪信息。

--porcelain

在进行dry-run时,以porcelain-ready格式提供输出。 有关详细信息,请参见git-status [1]。 Implies--dry-run。

--long

在进行dry-run时,,以长格式 long-format提供输出. Implies --dry-run.

-z

--null

显示shortporcelain格式状态输出时,逐字打印文件名并以NUL而不是LF终止输入。 如果未给出格式,则表示--porcelain输出格式。 如果不使用-z选项,则引用带有“不寻常”字符的文件名,如配置变量core.quotePath所述(参见git-config [1])。

-F <file>

--file=<file>

从给定文件中获取提交消息。 使用 - 从标准输入中读取消息。

--author=<author>

覆盖提交作者。 使用标准author <[email protected]>格式指定明确的作者。 否则,将<author>假定为一种模式,并用于搜索该作者的现有提交(即rev-list --all -i --author = <author>); 然后从发现的第一个此类提交中复制提交作者。

--date=<date>

覆盖提交中使用的作者日期。

-m <msg>

--message=<msg>

使用给定的<msg>作为提交消息。 如果给出了多个-m选项,则它们的值将串联为单独的段落。

-m选项与-c,-C和-F互斥。

-t <file>

--template=<file>

编辑提交消息时,请使用给定文件中的内容启动编辑器。 commit.template配置变量通常用于隐式地将此命令赋予命令。 此机制可用于希望引导参与者以什么顺序在消息中写些什么的项目。 如果用户退出编辑器而不编辑消息,则提交将中止。 当通过其他方式(如 -m或-F选项)发出消息时,这选项无效。

-s

--signoff

在提交日志消息的末尾,添加由提交者签名的行。

-n

--no-verify

此选项绕过pre-commit和commit-msg挂钩. See also githooks[5].

--allow-empty

通常,记录与唯一的父提交具有完全相同的树的提交是一个错误,并且该命令会阻止您进行此类提交。 此选项绕过安全性,主要供外国SCM接口脚本使用。

--allow-empty-message

像--allow-empty一样,此命令主要供外部SCM接口脚本使用。 它允许您使用空的提交消息创建提交,而无需使用git-commit-tree [1]等底层命令。

--cleanup=<mode>

此选项确定在提交之前应如何清除提供的提交消息。 <mode>可以是条strip,空格whitespace,普通字verbatim,剪刀scissors或默认值default。

  •     strip

删除开头和结尾的空行,结尾的空白,注释和折叠连续的空行。

  • whitespace

除不删除#commentary以外,其他与strip相同。

  • verbatim

完全不要更改消息。

  • scissors

与whitespace相同,除了如果要编辑消息,则以下一行中的所有内容(包括以下内容)都会被截断。 可以使用core.commentChar自定义“#”。

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

Same as strip if the message is to be edited. Otherwise whitespace.

The default can be changed by the commit.cleanup configuration variable (see git-config[1]).

-e    --edit

从-F选项指定的文件,-m命令行和 -C 提交对象获取的消息通常用作未修改的提交日志消息。 此选项使您可以进一步编辑从这些来源获取的消息。

--no-edit

使用选定的提交消息而无需启动编辑器。例如,git commit --amend --no-edit修改提交而不更改其提交消息。

--amend

通过创建新的提交来替换当前分支的尖端。 记录的树像往常一样准备好(包括-i和-o选项的作用以及显式pathspec),并且当未通过-m,-F,-c等命令行选项指定其他消息时,将原始提交的消息用作起点,而不是空消息。新提交的父代和作者与当前提交的父代和作者相同(--reset-author选项可以强制执行此操作)。

它大致相当于:

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

但可用于修改合并提交。

如果您修改已经发布的提交,则应该了解重写历史的含义。(See the "RECOVERING FROM UPSTREAM REBASE" section in git-rebase[1].)

--no-post-rewrite

绕过post-rewrite hook.

-i

--include

在从暂存的内容中进行提交之前,还要暂存命令行上给定路径的内容。 除非您要完成有冲突的合并,否则通常这不是您想要的。

-o

--only

通过获取命令行上指定的路径的更新的工作树内容来提交,而不考虑为其他路径暂存的任何内容。 如果在命令行上给出了任何路径,这是git commit的默认操作模式,在这种情况下可以省略此选项。 如果将此选项与--amend一起指定,则无需指定路径,该路径可用于修改最后一次提交而无需提交已经进行的更改。 如果与--allow-empty路径一起使用,则也不需要,并且将创建一个空的提交。

--pathspec-from-file=<file>

pathspec是通过<file>而不是命令行参数传递的。 如果<file>是 - 则使用标准输入。 pathspec元素由LF或CR / LF分隔。 可以按照配置变量core.quotePath的说明引用Pathspec元素(请参阅git-config [1])

--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>]

显示未跟踪的文件。

mode参数是可选的(默认为all),用于指定未跟踪文件的处理; 当不使用-u时,默认为正常normal,即显示未跟踪的文件和目录。

The possible options are:

  • no - 不显示未跟踪的文件

  • normal - 显示未跟踪的文件和目录

  • all - 还显示未跟踪目录中的单个文件。

可以使用git-config [1]中记录的status.showUntrackedFiles配置变量来更改默认值。

-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].

If specified twice, show in addition the unified diff between what would be committed and the worktree files, i.e. the unstaged changes to tracked files.

-q    --quiet

Suppress commit summary message.

--dry-run

不创建提交,而是显示要提交的路径的列表,本地更改的路径(将保留为未提交)和未跟踪的路径。

--status

使用编辑器准备提交消息时,请在提交消息模板中包含git-status [1]的输出。 默认值为on,但可用于覆盖配置变量commit.status。

--no-status

Do not include the output of git-status[1] in the commit message template when using an editor to prepare the default commit message.

-S[<keyid>]

--gpg-sign[=<keyid>]

GPG-sign commits. The keyid argument is optional and defaults to the committer identity; if specified, it must be stuck to the option without a space.

--no-gpg-sign

Countermand commit.gpgSign configuration variable that is set to force each and every commit to be signed.

--

Do not interpret any more arguments as options.

<pathspec>…​

在命令行上给出pathspec时,提交与pathspec匹配的文件的内容,而不记录已添加到索引中的更改。 这些文件的内容也将在之前已进行的内容的基础上为下一次提交而进行。

日期格式DATE FORMATS

The GIT_AUTHOR_DATEGIT_COMMITTER_DATE environment variables and the --date option support 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 email format as described by RFC 2822, for example Thu, 07 Apr 2005 22:13:13 +0200.

ISO 8601

Time and date specified by the ISO 8601 standard, for example 2005-04-07T22:13:13. The parser accepts a space instead of the T character as well.

Note

In addition, the date part is accepted in the following formats:YYYY.MM.DDMM/DD/YYYY and DD.MM.YYYY.
发布了243 篇原创文章 · 获赞 138 · 访问量 138万+

猜你喜欢

转载自blog.csdn.net/ystyaoshengting/article/details/104067528
今日推荐