Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git add Signed-off-by line using format.signoff not working

Tags:

git

format

config

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.

  1. When I set git config --global format.signoff true, and run git commit -m "modify something", I see no "Signed-off-by" in git log.
  2. If I use git commit -m -s "modify something", then "Signed-off-by" does show in git log.

Can anyone help?

like image 426
Venus Avatar asked Feb 22 '13 02:02

Venus


People also ask

What is signoff in git?

Sign-off is a line at the end of the commit message which certifies who is the author of the commit. Its main purpose is to improve tracking of who did what, especially with patches.

How do you git add and commit on same line?

git config --global alias. add-commit "! git add -A && git commit" (i.e. double quotes instead of single quotes) is what works on Windows.

Can you commit without adding?

Without adding any files, the command git commit won't work. Git only looks to the staging area to find out what to commit. Staging, or adding, files, is possible through the command line, and also possible with most Git interfaces like GitHub Desktop by selecting the lines or files that you'd like to stage.


1 Answers

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 its master branch)!

Save the following as .git/hooks/prepare-commit-msg or .git/hooks/commit-msg (see here for the differences) and make it executable.

#!/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 "$1" 
like image 141
stefanct Avatar answered Sep 25 '22 08:09

stefanct