使用 git 自动签署所有提交

tam*_*asd 12 git pgp

使用 git 1.7.9,可以使用-S选项签署提交。是否可以通过 将其设置为默认值git config --global

所以,而不是git commit -S -m 'Commit message',它会只是git commit -m 'Commit message'.

ric*_*ues 9

要自动签署所有未来的 git 提交,您可以定义一个全局别名。例如,要创建一个名为“c”的全局别名,您可以这样做:

$ git config --global alias.c 'commit -s'
Run Code Online (Sandbox Code Playgroud)

(请注意,在您输入问题时,要注销的提交开关是小写的“-s”而不是大写的“-S”)。

完成此操作后,您可以开始使用新创建的“c”别名进行提交。这是创建和提交一个名为“test.txt”的文件的示例,该文件将由提交者签署:

$ vim test.txt
[edit file]
$ git add test.txt
$ git c -m 'My commit message'
Run Code Online (Sandbox Code Playgroud)

如果您使用以下--pretty=fuller选项运行“git log”命令,您可以看到提交具有“Signed-off-by:”行:

$ git log --pretty=fuller
Run Code Online (Sandbox Code Playgroud)

  • `-s` 向提交添加一个“签名者”字段。`-S` 实际上是 PGP 签署提交,这是在 git 1.7.9 中添加的。此外,这不会对所有提交进行签名,而只会对用户直接使用 `git c` 命令生成的提交进行签名。在 rebase 中,当创建新提交时,这不会签署(或 PGP 签名)提交,除非您执行交互式 rebase 并手动提交每个更改。 (5认同)