Git在提交时将以#开头的行视为注释行。在使用票务跟踪系统时,试图将票号写在行首是非常令人讨厌的。

#123 salt hashed passwords

Git会简单地从提交消息中删除这一行。是否有一种方法来逃避散列?我试过了,但是都没用。#之前的空格被保留,所以这也不是解决问题的有效方案。


当前回答

这里的答案很好,也很详细,但是对于像我这样的git新手来说,定制git配置选项并不是那么明显。下面是一个从#改为;注释字符:

git config core.commentChar ";"

这就是你所需要做的。

其他回答

使用不同的票号前缀。或者在票号前加上一个词,比如“Bug #42”。或在行前加上一个空格字符;如果你想移除空白,你可以添加一个commit-hook。

我个人不希望这种提交消息操作由钩子完成,因为当它在你不想要的时候触发时,它会非常令人恼火。最简单的解决办法可能是重新思考这个问题。

您可以使用命令行选项-m:

git commit -m "#123 fixed"

Git commit -cleanup=剪刀应该被使用。它在2014.05.21被添加到Git v2.0.0中

从git提交——帮助

--cleanup=<mode>
  scissors
    Same as whitespace, except that everything from (and including) the line
    "# ------------------------ >8 ------------------------" is truncated if the message
    is to be edited. "#" can be customized with core.commentChar.

如果你正在做一个交互式的rebase,那么当你保存你的提交消息时,里面什么都没有(因为在开始的#已经使它成为一个注释,因此它被忽略了),git会告诉你该怎么做:

Aborting commit due to empty commit message.
Could not amend commit after successfully picking 5e9159d9ce3a5c3c87a4fb7932fda4e53c7891db... 123 salt hashed passwords
This is most likely due to an empty commit message, or the pre-commit hook
failed. If the pre-commit hook failed, you may need to resolve the issue before
you are able to reword the commit.
You can amend the commit now, with

        git commit --amend

Once you are satisfied with your changes, run

        git rebase --continue

所以,只需修改信息:

git commit --amend -m "#123 salt hashed passwords"

并继续调整基数:

git rebase --continue

! 是对历史的扩展所以才没用。

历史扩展是通过历史扩展字符的出现来介绍的,这就是!默认情况下。

你可以使用$和单引号(转义Bash单引号字符串中的单引号):

$ git commit -m $'#228 update to a new version! margin of error is 33% | 33^*0.22;'
# commit message: #228 update to a new version! margin of error is 33% | 33^*0.22;
$ git commit -m $'docs!: new API reference for GPS horse navigation'
# commit message: docs!: new API reference for GPS horse navigation

如果没有$和' but '加上":

$ git commit -m "docs!: new API reference for GPS horse navigation"
bash:  : unrecognized history modifier

如果与"和escape \一起使用(\仍然会在那里,或者我做错了什么):

$ git commit -m "docs\!: new API reference for GPS horse navigation"
# commit message: docs\!: new API reference for GPS horse navigation