Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git commit - treat # comments similar with or without message file

Tags:

git

I have staged a file readme.txt. When invoking

$ git commit

it opens my editor with a predefined message (the | in the first line I've added only to force stackoverflow to show this empty line):

|
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch master
# Changes to be committed:
#   modified:   readme.txt
#
# Untracked files:
#   message.txt
#

so I can enter the message

add readme.txt
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch master
# Changes to be committed:
#   modified:   readme.txt
#
# Untracked files:
#   message.txt
#

save and exit, the commit will be created with the message add readme.txt.

However, when having the same content in a file message.txt (including the # lines) and running

$ git commit --file message.txt

the commit will have the full content of the file as message, including all the comments.

How to tell Git to ignore the # lines in the specified message file as it does without the --file <message-file> parameter?

like image 247
Thomas S. Avatar asked Sep 07 '25 18:09

Thomas S.


1 Answers

This would then be

git stripspace --strip-comments < message.txt |
    git commit --file -
like image 78
j6t Avatar answered Sep 10 '25 02:09

j6t