Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a hash/pound symbol as the first character in a git commit message in vim

Tags:

git

vim

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 🤷‍♂️

like image 908
joshuatvernon Avatar asked Jun 28 '19 00:06

joshuatvernon


People also ask

What is hash In git commit?

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).

How do I commit a message in git?

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.

Does Git use the hash symbol as a comment character?

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.

How to change the hash of a git commit?

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

How to write a git commit message?

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.

What is a GitHub commit message and why is it important?

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.


2 Answers

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 '>'
like image 189
joshuatvernon Avatar answered Oct 24 '22 10:10

joshuatvernon


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

like image 37
Yannoff Avatar answered Oct 24 '22 10:10

Yannoff