如何使用 "git commit" 命令强制 "git commit -s"?

How can I force "git commit -s" using "git commit" command?

我正在寻找一种在提交时自动编写 Signed-off-by: 标记的方法。

我尝试通过 .git/config 文件 (Reference) 配置它。我把这些代码行:

[alias]
    commit = commit -s

这没有用。如下所述,您不能编辑 git 自己的别名(如提交)。(Reference)

我也试过使用命令(Reference)git config --global format.signoff true

同样没有效果。 This explains为什么。

我正在寻找任何可以自动放置标签并允许我直接在 git 上编辑提交消息而无需使用系统别名的解决方案。

使用提交挂钩实现此目的
https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks#_committing_workflow_hooks

prepare-commit-msg

The prepare-commit-msg hook is run before the commit message editor is fired up but after the default message is created.

It lets you edit the default message before the commit author sees it.

This hook takes a few parameters: the path to the file that holds the commit message so far, the type of commit, and the commit SHA-1 if this is an amended commit.

This hook generally isn’t useful for normal commits; rather, it’s good for commits where the default message is auto-generated, such as templated commit messages, merge commits, squashed commits, and amended commits.

You may use it in conjunction with a commit template to programmatically insert information.

[在最后一条评论后进行编辑]

我想如果我猜对了,你不能使用 'reserved' 单词作为 git 命令的别名。

但是如果你这样做

[alias]
  ci = commit -s

然后它会做你想让它做的事。