GitHub (probably, wrongly) uses #
's when referring to GitHub issues. So I would like to add a commit message that refers to the issue on the first line.
e.g.
#12: New commit
- Did a thing
- Did another thing
Vim/git ignores lines starting with #
's though so I'm not sure how to escape it 🤷♂️
Every commit to a repository has a unique identifier called a hash (since it is generated by running the changes through a pseudo-random number generator called a hash function).
The easiest way to create a Git commit with a message is to execute “git commit” with the “-m” option followed by your commit message. When using the Git CLI, note that you should restrict your commit message in order for it not to be wrapped.
And then I am struck with the sudden recollection that git uses the hash symbol as its comment character. (D’oh!) My commit messages starting with hashes were being treated as comments, leaving nothing behind for git to use.
If you amend the commit message, or the files in a commit, this will change the git hash. You can amend the last commit by running git commit --amend. This allows you to edit the message, what files and changes are included in a commit and even the author. All of these are things the hash is based on, so amending the commit will change the hash
If your commit message has a body, separate the body and the subject line using a blank line. Enough with rules. Let's do some practice. We will configure the default editor before creating and practicing git commit message using two repos. The first (local) repo helps us explore writing git commit messages on a simple personal project.
Git commit message is crucial in the git workflow as it determines the cleanliness of the history. Here is how it relates to the workflow. notifies git to create a repository in your current directory. It does that by creating a subdirectory called .git. that stores all information about the repository.
Git allows you to update the comment char from the #
symbol to any other. Then you can use the #
symbol.
e.g.
git config core.commentChar '>'
or optionally set it globally
git config --global core.commentchar '>'
The simplest way to avoid git
interpreting the issue number as a comment line, is to insert another character before, so the #
is not the leading character of the line (a space will do the trick).
Here is an example:
#45
will be seen as a comment
#45
Issue #45
will both be taken entirely as commit messages
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With