Git commit -无论是否使用消息文件,#注解都被视为类似

anauzrmj  于 2023-01-28  发布在  Git
关注(0)|答案(1)|浏览(90)

我暂存了一个文件readme.txt。调用

$ git commit

它会打开我的编辑器并显示一条预定义的消息(我在第一行中添加|只是为了强制stackoverflow显示这一空行):

|
# 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
#

这样我就可以输入消息

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
#

保存并退出,则将使用消息add readme.txt创建提交。
但是,当在文件message.txt中具有相同的内容(包括#行)并运行

$ git commit --file message.txt

提交将具有文件的全部内容作为消息,包括所有注解。
如何告诉Git忽略指定消息文件中的#行,就像没有--file <message-file>参数时那样?

gdrx4gfi

gdrx4gfi1#

这就是

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

相关问题