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

#123 salt hashed passwords

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


当前回答

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.

其他回答

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.

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

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

只需在# char之前使用空格字符开始提交消息即可。

然后git停止将该行视为注释,github可以毫无问题地使用散列票号。

Vim的默认语法高亮显示甚至通过将注释的颜色更改为内容的颜色来建议该功能。

我所有的提交都以#issueNumber开始,所以我把这个样板文件放在我的vim .git/hooks/commit-msg中:

NAME=$(git branch | grep '*' | sed 's/* //') 
echo "$NAME"' '$(cat "$1") > "$1"

假设我们有分支#15,我们让commit message添加新的很棒的功能。使用这种方法,最终提交消息将#15添加新的很棒的功能。

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

git commit -m "#123 fixed"