My client git version is 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
.
Can anyone help?
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 not in any git release yet (but in itsmaster
branch)!Save the following as
.git/hooks/prepare-commit-msg
or.git/hooks/commit-msg
(see here for the differences) and make it executable.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.See stefanct's answer for
commit-msg
client-side hook which would usegit interpret-trailers
.Original answer (2013)
format.signoff
is about patch (as illustrated, for instance, in this patch):It has no bearing on
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"), then you should sign them.
For the exact signification of
Signed-of-by
, see "What is the Sign Off feature in Git for?".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:
Then configure git to use that as a commit template. For example:
Make sure your project documents somewhere what signed-off-by means for the project. Here's some text you can copy into your CONTRIBUTING.md file:
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).