Start a git commit message with a hashmark (#)

knittl picture knittl · May 7, 2010 · Viewed 58.2k times · Source

Git treats lines starting with # as comment lines when committing. this is very annoying when working with a ticket tracking system, and trying to write the ticket number at the beginning of the line, e.g.

#123 salt hashed passwords

git will simply remove the line from the commit message. is there any way to escape the hash? i tried \ and !, but nothing works. whitespaces before # are preserved, so they aren't a working solution to the problem either.

Answer

CB Bailey picture CB Bailey · May 7, 2010

This behaviour is part of git commit's default 'clean-up' behaviour. If you want to keep lines starting with # you can use an alternative clean-up mode.

E.g.

git commit --cleanup=whitespace

If you do this you have to be careful to remove all # lines that you don't want to appear in the commit.