I was wondering how to sign(-s
) off previous commits that I have made in the past in git?
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
An interactive rebase with the -S
flag will do the job.
Let's say you need to sign off the last n commits (make sure to checkout the latest of those n commits).
Run:
$ git rebase -S -i HEAD~n
# The `-S` flag is important.
# It tells Git to sign the following commits.
This gives a list of the last n
commits.
Now, change pick
to edit
prefix for all the commits you want to sign.
Once done, close the editor. A new editor will open with everything about the commit.
Since nothing needs to be changed in the commit, save the file and exit the editor. You can also change the commit message while at it.
Repeat this for other commits.
To push the latest history, git push remote branch -f
.
There's one gotcha - it can rewrite your commits.
If you sign a 4-month old commit, it might overwrite its date and make it look like it was created today. So, not recommended when you want to preserve your commit history.