Git sign off previous commits?
I was wondering how to sign(-s
) off previous commits that I have made in the past in git?
To signoff the previous commit, use amend option:
git commit --amend --signoff
Edit: the amend does signoff only the latest commit. To signoff multiple commits, filter-branch
and interpret-trailers
as suggested by vonc et. al. should be used. Here is what worked for me.
First, configure git to replace the token sign
by Signed-off-by
. This has to be done only once and is needed in the next step.
git config trailer.sign.key "Signed-off-by"
The command git filter-branch
with the switch --msg-filter
will eval the filter once for each commit. The filter can be any shell command that receives the commit message on stdin and outputs on stdout. You can write your own filter, or use git interpret-trailers
, which is indepotent. Here is an example that will signoff the latest two commits of the current branch using the current user and email:
export SIGNOFF="sign: $(git config --get user.name) <$(git config --get user.email)>"
git filter-branch -f --msg-filter \
"git interpret-trailers --trailer \"$SIGNOFF\"" \
HEAD~2..HEAD
Note 1) Modifying commit messages change the commit id, which means pushing over already published branches will have to be forced either with --force
or better --force-with-lease.
Note 2) if you intend to write your custom script, beware that git filter-branch
changes the current directory to <repo>/.git-rewrite/t
. Using a relative path to the script won't usually work. Instead, the script should be in your $PATH
or provided as an absolute path.
Try this one to redo old commits with a -S
:
git filter-branch -f --commit-filter 'git commit-tree -S "$@"' HEAD
After that, you have to git push -f
. But be careful, the commit ids will change and other people will become out of sync.
These days (starting with Git 2.13) you can generally do something like
git rebase --signoff HEAD~2
to add Signed-off-by
footers to the last 2 commits (in this example).
If your range includes the root commit, add the --root
option to rebase
.
If anyone still looking for a better-automated way of signing off commits.
Try this:
git rebase --exec 'git commit --amend --no-edit -n -S' -i commit-hash
This will rebase everything till the commit-hash (X commits)
Then git push -f
is required to push back the change in history back to remote
For me just ammending signof, didn't actually verify my commits on github.
The solution that is worked for me is going back, and then sign each commit with -S
git commit --amend -S
Also if you check if your commit is actually signed, and your email/name is simply not appended, use this command
git show HEAD --show-signature
Extra tip: If you are already amending your commits, you may want your real name in them (see using git log
). You may be using your github handle name, which is not needed. Only correct email is needed and in field of username you should use your full name and github will track it correctly with your github handle name. So to correct your user name and sign last commit use:
git commit --amend --author="FULL NAME <email>" -S
and also set full name for user name in future by
git config --global user.name "FULL NAME"