8

When I tag versioned code in git, I like using bullet points in the tag message.

This can easily be done with annotated tags:

git tag -a v1.0.0

* Change number 1
* Change number 2
#
# Write a tag message
#

However, if I attempt the same tag with the -m option, the tag message is not what I expect:

git tag -a v1.0.0 -m "* Change number 1\n* Change number 2"

git show v1.0.0

...

* Change number 1\n* Change number 2
....

The '\n' was interpreted literally as the characters '\' and 'n' instead of a newline. I want to use the -m option so that I can automate the tagging process.

Is there any way to include actual newline characters using git tag with the -m option?

Eric Peterson
  • 143
  • 1
  • 6

4 Answers4

14

The closest solution I found is to use multiple -m options, one for each line. For example:

git tag -a v1.0.0 -m "* Change number 1" -m "* Change number 2"

from git-tag man page:

-m <msg>
   Use the given tag message (instead of prompting). If multiple
   -m options are given, their values are concatenated as separate
   paragraphs. (...)

UPDATE: Check "Add line break to git commit -m from command line" for more shell-based solutions.

Community
  • 1
  • 1
Aziz
  • 17,407
  • 5
  • 59
  • 66
  • Good answer. Oh the hidden treasures that can be found in the man pages. Thanks, Aziz! – Eric Peterson May 21 '12 at 17:53
  • 3
    This will put extra newlines between the messages, which may not be desirable. – Max Nanasy Sep 04 '12 at 21:22
  • My command: `git tag -a v1.1.0 -m "+ added highlight syntax for regular expressions in find and replace consoles," -m "+ added instructions about customization some graphic parameters for Windows 10 users."`. [**Result**](https://github.com/Kristinita/SashaSublime/releases/tag/v1.1.0). What I do wrong? Thanks. – Саша Черных Sep 21 '16 at 15:32
  • Help for me: `tag -a st3-1.1.0 -m "Version 1.1.0" -m "+ added highlight syntax for regular expressions in find and replace consoles," -m "+ added instructions about customization some graphic parameters for Windows 10 users."`. [**Result**](https://github.com/Kristinita/SashaSublime/releases/tag/st3-1.1.0). Thanks. – Саша Черных Sep 22 '16 at 06:57
4

Another alternative would be to put the formatted message in a (temporary) file and use git tag -F <filename> <tag> to read the message from that file.

twalberg
  • 52,775
  • 9
  • 80
  • 80
4

Best solution is to write your commit and tag messages right from your default code editor.

  • Use command git tag -a v1.0.0 and hit enter. Don't write -m
  • It will open up your default code editor, write message, save and close the file.
  • Command line will be resumed.
Muhammad Tarique
  • 1,131
  • 1
  • 10
  • 14
0

Assuming you're using a unix shell, your syntax for newline is wrong.

git tag -a v1.0.0 -m "* Change number 1
* Change number 2"

should work.

Max Nanasy
  • 5,257
  • 6
  • 30
  • 34
  • 2
    What about `git tag -a v1.0.0 -m $'* Change number1\n* Change number 2'` ? – Damien Flament Jan 12 '20 at 13:33
  • @DamienFlament That works as well, at least in bash. Although I just tried my answer's syntax in csh, and it doesn't work there, so "unix shell" isn't accurate for my answer either :P – Max Nanasy Jan 15 '20 at 18:44