Use of an exclamation mark in a Git commit message via the command line

后端 未结 6 811
面向向阳花
面向向阳花 2020-12-07 12:52

How do I enter an exclamation point into a Git commit message from the command line?

It is possible to escape the exclamation point with a backslash, but then the ba

6条回答
  •  旧时难觅i
    2020-12-07 13:20

    If you need to use double quotes and the ! is the last character in the message, just keep the ! outside of the quotes, since we're only using quotes so that the spaces get included in the message.

    git commit -m "Reverting last commit because I don't like it"!
    

    If you need to include ! mid string, you can use single quotes but if you need to use a literal single quote, you'll need to close your quote, then put the ' outside of the string by escaping it. So, let's say your message is I don't like it! Reverting again!, this can be composed with 'I don' + \' + 't like it! Reverting again!'

    git commit -m 'I don'\''t like it! Reverting again!'
    

    Anything more complicated than this, you're probably better off with git commit and letting git invoke your default text editor :)

提交回复
热议问题