【问题标题】:How to let VS Code's Commit UI support a `#` in the commit message?如何让 VS Code 的 Commit UI 在提交信息中支持 `#`?
【发布时间】:2020-03-09 07:58:42
【问题描述】:

我需要遵循以# 开头的 git commit 消息格式(例如#1234 ...)。

这不是与Start a git commit message with a hashmark (#) 重复,因为我知道commentchar 并且我已经将git 配置为使用不同的评论字符:

gino@myrepo$ git config --global --get core.commentchar
;
gino@myrepo$ git config --get core.commentchar
;

我还确认,如果我从命令行提交,它可以工作:

gino@myrepo$ git log
Author: ...
Date:   Wed Nov 13 21:59:40 2019 +0900

    # Test `git commit` from terminal
    # These 2 lines should not be treated as comments

问题是当我尝试从VS Code's Commit UI 提交时:

VS Code 的 Git 似乎不支持 # 不是注释的配置,因为当我检查 git log 时,它只显示第 2 行:

gino@myrepo$ git log
commit 1254416d309588293372b96fd1f71e30af51b1fe (HEAD -> master)
Author: ...
Date:   Wed Nov 13 22:23:17 2019 +0900

    These lines should be details.

当我尝试使用单行消息 (#4567: blah) 时,情况更糟。提交 UI 不允许我提交(单击提交按钮时没有任何反应)并且 Command Palette > Git: Commit 命令将简单地中止提交(可能因为它被视为空提交消息)。

如何让 VS Code 识别自定义 commentchar 设置?

注意事项:

  • 我知道 VS Code 使用我的 git config(全局或本地),因为当我尝试更改其他设置(例如 user.name)时,它会正确应用它
  • 它不是 Start a git commit message with a hashmark (#) 的重复,因为我说的是通过 VS Code 的 Commit UI,而不是通过命令行提交
  • 我找不到 VS Code > 与提交消息相关的 Git 设置
  • 我正在使用 VS Code 1.40.0

【问题讨论】:

  • 你试过用反斜杠 \# 转义它吗?不确定这是否可行。
  • @Bauke:好吧,#-line 行出现了,但提交消息变成了\#...,这也不正确。
  • 我发现 this issue 似乎有你想要修复的东西。不过我不知道什么时候可以使用。
  • @Philippe, @phd:不,这不是重复的,因为正如我在文章开头所解释的那样,我知道如何通过命令行进行操作(使用 @987654343 @ git config)并且我已经确认它正在工作。我的实际问题(我在帖子的其余部分和标题中描述了与通过 VS Code 的源代码控制 UI 执行相同操作有关,这似乎不尊重 commentchar 配置。

标签: git visual-studio-code vscode-settings git-commit


【解决方案1】:

这显然是 1.40.0 版本的 VS Code 的回归错误。
(感谢@Bauke 指点我相关的 Github 问题。)

https://github.com/microsoft/vscode/issues/84201#issuecomment-552830865:

#6403 的修复使得输入框现在处理开始的行 # 作为 cmets。

它随后作为 1.40.1 版本的 VS Code 的一部分“修复”。
(更新 1.40.1:更新解决了这些issues。)

https://github.com/microsoft/vscode/issues/84201#issuecomment-552840563

您应该能够提交以# 开头的单行并且 后跟任何内容。

您应该能够提交以# 开头的行的消息 后跟数字。以# 开头且后面没有数字的行 将被注释掉。例如,以下提交消息:

first line
second line
#third line
# fourth line
# 5th line
#6th line
#7 th line
#8

应该变成:

first line
second line
#6th line
#7 th line
#8

因为所有其他行都应该被注释掉。

我说“已修复”,因为从关于 Github 问题的讨论来看,提交 UI 输入框似乎没有完全遵循或使用 git 的 commentchar 配置,并且它有自己的解析提交消息的哪些部分是 cmets。

在我的情况下,由于我的提交消息遵循格式“以# 开头并后跟任何内容的单行”,所以它似乎是有效的。但是,如果您使用的是不符合输入框正则表达式规则的其他格式,那么它将无法正常工作。

【讨论】:

    猜你喜欢
    • 2020-11-28
    • 2020-03-14
    • 2020-09-12
    • 2021-11-01
    • 1970-01-01
    • 2020-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多