예배 규칙서 찾다
Guides gitattributes giteveryday gitglossary gitignore gitmodules gitrevisions gittutorial gitworkflows Administration git archive git bundle git clean git filter-branch git fsck git gc git instaweb git reflog Basic Snapshotting git add git commit git diff git mv git reset git rm git status Branching and Merging git branch git checkout git log git merge git mergetool git stash git tag Debugging git bisect git blame git grep Email git am git format-patch git request-pull git send-email External Systems git fast-import git svn Getting and Creating Projects git clone git init Git git annotate git archimport git bisect-lk2009 git check-attr git check-mailmap git check-ref-format git checkout-index git cherry git citool git column git credential git credential-cache git credential-store git cvsexportcommit git cvsimport git cvsserver git diff-files git diff-tree git difftool git fast-export git fetch-pack git fmt-merge-msg git get-tar-commit-id git gui git http-backend git http-fetch git http-push git imap-send git index-pack git interpret-trailers git ls-remote git ls-tree git mailinfo git mailsplit git merge-file git merge-index git merge-one-file git merge-tree git mktag git mktree git name-rev git notes git p4 git pack-objects git pack-redundant git pack-refs git parse-remote git patch-id git prune git prune-packed git quiltimport git receive-pack git remote-ext git remote-fd git remote-testgit git repack git replace git rerere git send-pack git sh-i18n git sh-setup git shell git show-branch git show-index git stripspace git unpack-file git unpack-objects git upload-archive git upload-pack git var git verify-commit git verify-tag git whatchanged git worktree Inspection and Comparison git describe git shortlog git show Miscellaneous api credentials api index gitcli gitcore tutorial gitcredentials gitcvs migration gitdiffcore githooks gitk gitnamespaces gitremote helpers gitrepository layout gitsubmodules gittutorial 2 gitweb gitweb.conf pack format User Manual Patching git apply git cherry-pick git rebase git revert Plumbing Commands git cat-file git check-ignore git commit-tree git count-objects git diff-index git for-each-ref git hash-object git ls-files git merge-base git read-tree git rev-list git rev-parse git show-ref git symbolic-ref git update-index git update-ref git verify-pack git write-tree Server Admin git daemon git update-server-info Setup and Config git git config git help Sharing and Updating Projects git fetch git pull git push git remote git submodule
문자

名称

git-interpret-trailers  - 帮助将结构化信息添加到提交消息中

概要

git interpret-trailers [--in-place] [--trim-empty] [(--trailer <token>[(=|:)<value>])…] [<file>…]

描述

在提交消息的其他自由格式部分的末尾,帮助添加与RFC 822电子邮件标题类似的trailers行。

如果没有指定<file>,该命令将从<file>参数或标准输入读取一些补丁或提交消息。然后该命令将使用该--trailer选项传递的参数(如果有)应用于每个输入文件的提交消息部分。结果发送到标准输出。

一些配置变量控制--trailer参数应用于每个提交消息的方式以及提交消息中任何现有的尾部改变的方式。他们还可以自动添加一些预告片。

默认情况下,一个<token>=<value><token>:<value>利用给定的参数--trailer在现有拖车之后将附加仅当最后拖车具有不同的(<令牌>,<值>)对(或如果不存在现有拖车)。<token>和<value>部分将被修剪以删除开始和结尾的空白,并且生成的修剪后的<token>和<value>将出现在消息中,如下所示:

token: value

这意味着修剪后的<token>和<value>将被分隔': '(一个冒号后跟一个空格)。

默认情况下,新的预告片将出现在所有现有预告片的末尾。如果没有现有的预告片,则新的预告片将出现在输出的提交消息部分之后,并且如果在提交消息部分末尾没有只有空格的行,则在新预告片之前将添加一个空白行。

通过查找一组一条或多条(i)都是预告片,或(ii)至少包含一个由 Git 生成或用户配置的预告片并由至少25%预告片组成的一组或多行的线,从输入消息中提取现有预告片。该组必须在一个或多个空白(或仅空白)行之前。该组必须位于消息的末尾,或者是以一行开头的行之前的最后一个非空白行---。这三个减号开始消息的补丁部分。

阅读预告片时,令牌,分隔符和值之后可能有空格。标记和值中还可能有空格。该值可以分成多行,每个后续行以空格开头,如 RFC 822中的“折叠”。

请注意,trailers不要遵循并且不打算遵循 RFC 822标头的许多规则。例如,他们不遵循编码规则和其他许多规则。

选项

--in-place

编辑文件。

--trim-empty

如果任何预告片的<value>部分只包含空格,则整个预告片将从结果消息中删除。这适用于现有的拖车以及新的拖车。

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

指定应作为尾部应用于输入消息的(<token>,<value>)对。请参阅此命令的说明。

配置变量

trailer.separators

该选项告诉哪些字符被识别为拖车分隔符。默认情况下,只有:被识别为一个尾部分隔符,除了=在命令行上始终接受,以便与其他 git 命令兼容。

此选项给出的第一个字符将是当此预告片的配置中未指定另一个分隔符时使用的默认字符。

例如,如果此选项的值是“(%)= $”,则仅使用格式线<token><sep><value>与<月>含%=$然后空格将被视为拖车。并且%将作为默认分隔符,因此默认拖放器将显示为:(<token>% <value>一个百分号和一个空格将出现在令牌和值之间)。

trailer.where

这个选项告诉将添加一个新的预告片。

这可以是end,这是默认的startafter或者before

如果是end,则每个新的预告片将出现在现有预告片的末尾。

如果是start,则每个新的预告片将出现在现有预告片的开始而不是结尾。

如果是after,则每个新的预告片将在具有相同<令牌>的最后一个预告片之后出现。

如果是before,则每个新的预告片将在具有相同的<令牌>的第一个预告片之前出现。

trailer.ifexists

此选项可以选择在消息中至少有一个具有相同<token>的预告片时执行的操作。

此选项的有效值是:addIfDifferentNeighbor(这是默认), addIfDifferentaddreplacedoNothing

使用时addIfDifferentNeighbor,只有在没有相同(<token>,<value>)对的拖车位于新拖车添加行的上方或下方时,才会添加新拖车。

使用时addIfDifferent,只有在消息中没有具有相同(<token>,<value>)对的尾部时,才会添加新预告片。

随着add,即使一些具有相同(<token>,<value>)对的预告片已经在消息中,也会添加新的预告片。

同时replace,具有相同<令牌>的现有预告片将被删除,新预告片将被添加。已删除的预告片将是最接近的一个(具有相同的<令牌>)以添加新的预告片。

随着doNothing,什么都不会做;如果消息中已经有一个具有相同的<token>,则不会添加新的预告片。

trailer.ifmissing

通过此选项,可以选择在消息中还没有具有相同<token>的任何预告片时执行的操作。

此选项的有效值为:add(是默认值)和doNothing

随着add,一个新的预告片将被添加。

随着doNothing,什么都不会做。

trailer.<token>.key

key将在预告片中用来代替<token>。在这个键的最后,可以出现分隔符,然后出现一些空格字符。默认情况下,唯一有效的分隔符是:,但可以使用trailer.separatorsconfig变量更改。

如果有分隔符,则在添加预告片时,将使用该键代替<token>和默认分隔符。

trailer.<token>.where

此选项采用与trailer.where配置变量相同的值,并覆盖具有指定<token>的拖车的该选项指定的内容。

trailer.<token>.ifexist

此选项采用与trailer.ifexist配置变量相同的值,并覆盖具有指定<token>的拖车的该选项指定的内容。

trailer.<token>.ifmissing

此选项采用与trailer.ifmissing配置变量相同的值,并覆盖具有指定<token>的拖车的该选项指定的内容。

trailer.<token>.command

该选项可用于指定将被调用以自动添加或修改具有指定的<token>的尾部的 shell 命令。

如果指定了此选项,则行为就好像<token>=<value>在命令行的开始处添加了一个特殊参数,其中<value>将被视为指定命令的标准输出,并且任何前导和尾随空格都将被裁掉。

如果命令包含$ARG字符串,则在命令启动之前,该字符串将替换为具有相同<标记>的现有预告片的<值>部分(如果有)。

如果某些<token>=<value>参数也通过命令行传递,trailer.<token>.command则配置a时,也会为每个参数执行该命令。并且这些参数的<value>部分(如果有的话)将用于替换$ARG命令中的字符串。

示例

  • sign使用Signed-off-by密钥配置预告片,然后将两个预告片添加到消息中:$ git config trailer.sign.key“Signed-off-by”$ cat msg.txt主题消息$ cat msg.txt | git interpret-trailers --trailer'sign:Alice alice@example.com '--trailer'sign:Bob bob@example.com'subject message签名:Alice alice@example.com签名:鲍勃bob@example.com

  • 使用该--in-place选项即可编辑消息文件:

$ cat msg.txt主题信息签名:Bob bob@example.com $ git interpret-trailers --trailer'Acked-by:Alice alice@example.com'--in-place msg.txt $ cat msg .txt主题消息签名:Bob bob@example.com Acked-by:Alice alice@example.com

  • 提取最后一次提交的补丁,并添加CcReviewed-by拖车到它:$ git的格式补丁-1 0001-foo.patch $ git的解释拖车--trailer“抄送:爱丽丝alice@example.com ” --trailer '评论者:Bob bob@example.com'0001-foo.patch > 0001-bar.patch

  • sign只有当没有'Signed-off-by:'时,才会使用命令配置尾部,以自动添加'Signed-off-by:'和作者信息,并显示其工作原理:

$ git config trailer.sign.key "Signed-off-by: " $ git config trailer.sign.ifmissing add $ git config trailer.sign.ifexists doNothing $ git config trailer.sign.command 'echo "$(git config user.name) <$(git config user.email)>"' $ git interpret-trailers <<EOF > EOF  Signed-off-by: Bob bob@example.com $ git interpret-trailers <<EOF > Signed-off-by: Alice alice@example.com > EOF  Signed-off-by: Alice alice@example.com

  • 在这个字符后面配置一个fix包含一个#没有空格的键的尾部,并显示它的工作原理:$ git config trailer.separators“:#”$ git config trailer.fix.key“Fix#”$ echo“subject”| git interpret-trailers --trailer fix = 42主题修复#42

  • see使用命令配置尾部以显示相关提交的主题,并显示其工作原理:

$ git config trailer.see.key“另请参阅:”$ git config trailer.see.ifExists“替换”$ git config trailer.see.ifMissing“doNothing”$ git config trailer.see.command“git log -1  - -oneline --format = \“%h(%s)\”--abbrev-commit --abbrev = 14 \ $ ARG“$ git interpret-trailers << EOF> subject>> message>>请参阅:HEAD〜2 > EOF主题信息也参见:fe3187489d69c4(相关提交的主题)

  • 使用一些空值的预告片配置提交模板(使用 sed 在预告结束处显示并保留尾部空格),然后配置一个git interpret-trailers用于删除空值预告片的提交消息钩子并添加git-version预告片:

$ sed -e 's/ Z$/ /' >commit_template.txt <<EOF > ***subject*** > > ***message*** > > Fixes: Z > Cc: Z > Reviewed-by: Z > Signed-off-by: Z > EOF $ git config commit.template commit_template.txt $ cat >.git/hooks/commit-msg <<EOF > #!/bin/sh > git interpret-trailers --trim-empty --trailer "git-version: \$(git describe)" "\$1" > "\$1.new" > mv "\$1.new" "\$1" > EOF $ chmod +x .git/hooks/commit-msg

이전 기사: 다음 기사: