git add Signed-off-by line using format.signoff 不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15015894/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git add Signed-off-by line using format.signoff not working
提问by Venus
My client git version is 1.7.0.4.
我的客户端 git 版本是 1.7.0.4。
I want to automatically add a "Signed-off-by" line for the committer at the end of the commit log message when commit a message.
我想在提交消息时在提交日志消息的末尾自动为提交者添加一个“签名者”行。
- When I set
git config --global format.signoff true
, and rungit commit -m "modify something"
, I see no "Signed-off-by" ingit log
. - If I use
git commit -m -s "modify something"
, then "Signed-off-by" does show ingit log
.
- 当我设置
git config --global format.signoff true
并运行时git commit -m "modify something"
,我在git log
. - 如果我使用
git commit -m -s "modify something"
,则“签名者”确实会显示在git log
.
Can anyone help?
任何人都可以帮忙吗?
采纳答案by VonC
Update for Git 2.14.x/2.15: as I mentioned in "Git - Detect if commit is signed off programmatically", you will be able to parse a commit message trailer for Signed-off-By
line.
Git 2.14.x/2.15 更新:正如我在“ Git - 检测提交是否以编程方式签署”中所述,您将能够解析行的提交消息预告片Signed-off-By
。
"
git interpret-trailers
" has been taught a "--parse
" and a few other options to make it easier for scripts to grab existing trailer lines from a commit log message.
“
git interpret-trailers
”已经学会了“--parse
”和其他一些选项,使脚本更容易从提交日志消息中获取现有的预告片行。
See stefanct's answerfor commit-msg
client-side hookwhich would use git interpret-trailers
.
见stefanct的回答对commit-msg
客户端钩它将使用git interpret-trailers
。
Original answer (2013)
原始答案 (2013)
format.signoff
is about patch(as illustrated, for instance, in this patch):
format.signoff
是关于补丁(如图所示,例如,在这个补丁中):
format.signoff
A boolean value which lets you enable the -s/--signoff option of
format-patch
by default
一个布尔值,可让您
format-patch
默认启用 -s/--signoff 选项
It has no bearing on git commit -s
.
它与 无关git commit -s
。
In other words, you don't have to signoff every commit, but when you are publishing them as patch for others to use (as in "git: submitting patches"), thenyou should sign them.
换句话说,您不必对每个提交都进行签名,但是当您将它们作为补丁发布供其他人使用时(如“ git:提交补丁”),那么您应该对它们进行签名。
For the exact signification of Signed-of-by
, see "What is the Sign Off feature in Git for?".
有关 的确切含义Signed-of-by
,请参阅“ Git 中的 Sign Off 功能是什么?”。
回答by stefanct
There is now an easy way to automatically sign-off any commit that is not already signed-off by using hooks and the git-interpret-trailers
command. In the upcoming version 2.15 of git the command allows to trivially check for an existing sign-off (no matter what's its value/author is) and add yours if there is non yet. As of October 2017 the required code is notin any git release yet (but in its master
branch)!
现在有一种简单的方法可以使用钩子和git-interpret-trailers
命令自动签署任何尚未签署的提交。在即将发布的 git 2.15 版本中,该命令允许简单地检查现有的签名(无论其值/作者是什么),如果还没有,则添加您的签名。截至 2017 年 10 月,所需的代码尚未出现在任何 git 版本中(但在其master
分支中)!
Save the following as .git/hooks/prepare-commit-msg
or .git/hooks/commit-msg
(see herefor the differences) and make it executable.
将以下内容另存为.git/hooks/prepare-commit-msg
或.git/hooks/commit-msg
(请参阅此处了解差异)并使其可执行。
#!/bin/sh
NAME=$(git config user.name)
EMAIL=$(git config user.email)
if [ -z "$NAME" ]; then
echo "empty git config user.name"
exit 1
fi
if [ -z "$EMAIL" ]; then
echo "empty git config user.email"
exit 1
fi
git interpret-trailers --if-exists doNothing --trailer \
"Signed-off-by: $NAME <$EMAIL>" \
--in-place ""
回答by user45404
You can signoff by default in a project by creating a file (say "~/MYPROJECT/git-template") that contains some blank lines and the signed-off-by text like this:
默认情况下,您可以通过创建一个包含一些空行和签名文本的文件(例如“~/MYPROJECT/git-template”)在项目中进行签名,如下所示:
Signed-off-by: Your Name <[email protected]>
Then configure git to use that as a commit template. For example:
然后配置 git 以将其用作提交模板。例如:
git config commit.template ~/MYPROJECT/git-template
Make sure your project documentssomewhere what signed-off-by means for the project. Here's some text you can copy into your CONTRIBUTING.md file:
确保您的项目文件什么地方签断,借助于该项目。以下是您可以复制到 CONTRIBUTING.md 文件中的一些文本:
All contributions (including pull requests) must agree to the Developer Certificate of Origin (DCO) version 1.1. This is exactly the same one created and used by the Linux kernel developers and posted on http://developercertificate.org/. This is a developer's certification that he or she has the right to submit the patch for inclusion into the project. Simply submitting a contribution implies this agreement, however, please include a "Signed-off-by" tag in every patch (this tag is a conventional way to confirm that you agree to the DCO).
所有贡献(包括拉取请求)都必须同意开发者原产地证书 (DCO) 1.1 版。这与 Linux 内核开发人员创建和使用并发布在http://developercertificate.org/上的完全相同。这是开发人员证明他或她有权提交补丁以包含到项目中的证明。简单地提交贡献就意味着本协议,但是,请在每个补丁中包含一个“签字人”标签(此标签是确认您同意 DCO 的常规方式)。