Home Explore Blog CI



git

5th chunk of `Documentation/git-interpret-trailers.adoc`
46ee17ebfcc33a0fd9b75996d9ad63594b92de5b702cdb1a0000000100000c80
 text

Signed-off-by: Alice <alice@example.com>
$ git interpret-trailers --trailer sign <msg2.txt
subject

body text

Signed-off-by: Alice <alice@example.com>
------------

* Configure a 'fix' trailer with a key that contains a '#' and no
  space after this character, and show how it works:
+
------------
$ git config trailer.separators ":#"
$ git config trailer.fix.key "Fix #"
$ echo "subject" | git interpret-trailers --trailer fix=42
subject

Fix #42
------------

* Configure a 'help' trailer with a cmd use a script `glog-find-author`
  which search specified author identity from git log in git repository
  and show how it works:
+
------------
$ cat ~/bin/glog-find-author
#!/bin/sh
test -n "$1" && git log --author="$1" --pretty="%an <%ae>" -1 || true
$ cat msg.txt
subject

body text
$ git config trailer.help.key "Helped-by: "
$ git config trailer.help.ifExists "addIfDifferentNeighbor"
$ git config trailer.help.cmd "~/bin/glog-find-author"
$ git interpret-trailers --trailer="help:Junio" --trailer="help:Couder" <msg.txt
subject

body text

Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Christian Couder <christian.couder@gmail.com>
------------

* Configure a 'ref' trailer with a cmd use a script `glog-grep`
  to grep last relevant commit from git log in the git repository
  and show how it works:
+
------------
$ cat ~/bin/glog-grep
#!/bin/sh
test -n "$1" && git log --grep "$1" --pretty=reference -1 || true
$ cat msg.txt
subject

body text
$ git config trailer.ref.key "Reference-to: "
$ git config trailer.ref.ifExists "replace"
$ git config trailer.ref.cmd "~/bin/glog-grep"
$ git interpret-trailers --trailer="ref:Add copyright notices." <msg.txt
subject

body text

Reference-to: 8bc9a0c769 (Add copyright notices., 2005-04-07)
------------

* Configure a 'see' trailer with a command to show the subject of a
  commit that is related, and show how it works:
+
------------
$ cat msg.txt
subject

body text

see: HEAD~2
$ cat ~/bin/glog-ref
#!/bin/sh
git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14
$ git config trailer.see.key "See-also: "
$ git config trailer.see.ifExists "replace"
$ git config trailer.see.ifMissing "doNothing"
$ git config trailer.see.cmd "glog-ref"
$ git interpret-trailers --trailer=see <msg.txt
subject

body text

See-also: fe3187489d69c4 (subject of related commit)
------------

* Configure a commit template with some trailers with empty values
  (using sed to show and keep the trailing spaces at the end of the
  trailers), then configure a commit-msg hook that uses
  'git interpret-trailers' to remove trailers with empty values and
  to add a 'git-version' trailer:
+
------------
$ cat temp.txt
***subject***

***message***

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

SEE ALSO
--------
linkgit:git-commit[1], linkgit:git-format-patch[1], linkgit:git-config[1]

GIT
---
Part of the linkgit:git[1] suite

Title: Git Trailers Configuration and Usage Examples
Summary
The text provides various examples of configuring and using Git trailers, including adding, modifying, and removing trailers, as well as using custom scripts and commands to automate trailer management, and demonstrates how to integrate trailers with other Git features such as commit templates and hooks.