使用 git gui 从 git commit 中删除注释

问题描述 投票:0回答:1

我正在使用 git 提交模板来标准化我的提交,但是注释行(以

#
开头)在提交后不会被删除。

我可以配置

git gui
以忽略这些行吗?我使用
git gui
作为提交编辑器。

我使用以下方式配置提交模板:

git config --global commit.template C:\Users\Name\.gitmessage

我的

.gitmessage
文件:

#<-------------( Title: 50 chars )-------------->#
# Title/Summary/Imperative/Captilized/No period

# remember blank line between title and body

#<-------------( Body: wrap it to about 72 chars or so )-------------->#
# Body: Explain *what* and *why* (not *how*). Include task ID (issue).
# Explain the problem that this commit is solving. Focus on why you
# are making this change as opposed to how (the code explains that).
# Are there side effects or other unintuitive consequences of this
# change? Here's the place to explain them.

# <blank line>

# Co-authored-by: name <[email protected]>

这个想法是模板的所有行都不包含在提交中,以

#
开头的行将被忽略。

编辑:

使用 VS Code 作为主编辑器效果很好。

$ git config --global core.editor "code --wait"

git git-gui
1个回答
0
投票

我遇到了同样的问题,事实证明

commit-msg
git hook 被允许就地编辑消息文件。所以我添加了以下钩子,现在我的模板中的注释已通过 git gui 正确删除:

#!/usr/bin/env bash
sed -i '/^[[:space:]]*#.*$/d' "$1"

注意:

git commit
的实际逻辑不会删除
#
不在第一列中的行,正如我的示例(仅)允许其前面有空格。

© www.soinside.com 2019 - 2024. All rights reserved.