Thomas S.
Thomas S.

Reputation: 6345

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

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?

Upvotes: 4

Views: 65

Answers (1)

j6t
j6t

Reputation: 13387

This would then be

git stripspace --strip-comments < message.txt |
    git commit --file -

Upvotes: 4

Related Questions