git - 转义 git 提交消息中的注释字符 (#)

标签 git escaping

<分区>

我已将 mcedit 设置为 git 提交消息的编辑器。默认情况下,它会忽略以 # 字符开头的任何行。不管这看起来多么奇怪,我需要能够让我的提交消息看起来像这样:

#FOO-123: Implement bar foo

Committing work in progress

#FOO-123: ... 实际上是我们跟踪器中问题的键 + 标题。跟踪器可以自动获取这些提交消息并将它们添加到问题中。

不幸的是,第一行被当作注释而被忽略。

我不想通过添加 -m 从命令行提交,因为当你有多行时它不方便/丑陋。

我该如何解决这个问题?

最佳答案

您可以尝试为提交消息中的注释定义不同的字符:

git config core.commentchar <another char>

正如我在“Start a git commit message with a hashmark (#)”中提到的,此设置自 git 1.8.2(2013 年 2 月)起可用。

在你的情况下:

git config core.commentchar "*"

请注意,理论上您可以放置一个 core.commentchar 单词(多个字符),但 git 2.0.x/2.1 会更严格。

参见 commit 50b54fd通过 Nguyễn Thái Ngọc Duy (pclouds) :

配置:严格控制 core.commentChar

We don't support comment strings (at least not yet). And multi-byte character encoding could also be misinterpreted.

The test with two commas is updated because it violates this. It's added with the patch that introduces core.commentChar in eff80a9 (Allow custom "comment char" - 2013-01-16). It's not clear to me why that behavior is wanted.


poke还提到 in the comments更改 commit template :

When editing the commit message, start the editor with the contents in the given file.
The commit.template configuration variable is often used to give this option implicitly to the command.


请注意,Git 2.23(2019 年第 3 季度)修复了一个错误,因为“git interpret-trailers”始终将 '#' 视为注释字符,而不管 core.commentChar 设置,已更正。

参见 commit 29c83fc (2019 年 6 月 19 日)作者:Jeff King (peff) .
(由 Junio C Hamano -- gitster -- merge 于 commit 3a50607 ,2019 年 7 月 9 日)

interpret-trailers: load default config

The interpret-trailers program does not do the usual loading of config via git_default_config(), and thus does not respect many of the usual options.
In particular, we will not load core.commentChar, even though the underlying trailer code uses its value.

This can be seen in the accompanying test, where setting core.commentChar to anything besides "#" results in a failure to treat the comments correctly.

关于git - 转义 git 提交消息中的注释字符 (#),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22936252/

相关文章:

git - 在 Windows 版 GitHub 中编辑不正确的提交消息

git - 在不破坏文件历史记录的情况下 merge 两个 Git 存储库

github - 如何转义 Markdown 表中代码语句中的管道字符?

Java等价于JavaScript unescape函数

node.js - 维护单独的 git 分支 - 一个用于 heroku,另一个用于 github

linux - git 可以使用基于补丁/差异的存储吗?

Ruby:转义字符串中的特殊字符

c++ - 在运行时使用 C++ 使用转义序列

eclipse - egit merge 模式是什么意思?

Ruby:将转义字符串写入 YAML