Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: start a comment with # when using vim

Tags:

git

comments

vim

I usually write git comment by starting with a issue code, like this:

#3533: Fixed VIB (Very Important Bug)

When I perform a commit from command line I write

git commit -a -m "#3533: Fixed VIB (Very Important Bug)"

and everything is fine. When I perform a merge, or a interactive rebase, I use vim. After rebasing vim appears and I can add a commit, but lines starting with # are considered comments.

# This is a combination of 3 commits.
# The first commit's message is:

VIB resolved

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date:      Fri Jun 23 11:31:12 2017 +0200
#
# interactive rebase in progress; onto 7832e4d
# Last commands done (3 commands done):
#    s 536d248 Added space
#    s ae41f15 Removed space
# No commands remaining.
# You are currently rebasing branch 'RM-3539' on '7832e4d'.
#
# Changes to be committed:
#   modified:   VIBfile.m
#

So how can I start a comment with # character using Vim?

like image 326
Jepessen Avatar asked Nov 25 '25 07:11

Jepessen


1 Answers

You can use the core.commentchar config setting for this. e.g. git -c core.commentchar=$ commit would allow you to use # in the commit message. You can also set core.commentchar to auto in your gitconfig, and git will use a character that is never at the start of a commit message as comment char.

See also the git config documentation.

like image 133
Tommy Avatar answered Nov 27 '25 04:11

Tommy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!