I'm looking for a way to replicate what git commit -S does but on a specific commit, by giving its SHA for instance.
Is it possible?
I'm looking for a way to replicate what git commit -S does but on a specific commit, by giving its SHA for instance.
Is it possible?
Signing a commit will change the commit metadata, and thus change the underlying SHA1 commit ID. As you probably know, for Git, this has the same consequence of trying to change the contents of your history.
If you want to just re-sign your last commit you could run:
git commit -S --amend
If you want to re-sign a commit in the middle of your history you could do a couple of things, all of them being a bit nasty if you ask me:
reset --soft to the commit you want to sign. Run git commit -S --amend and then commit all the staged changes. This would merge all your history after that commit into a single commitreset --hard to the commit you want to sign. Sign it, and if you want to perserve commit history you could now git cherry-pick NEXTCOMMIT -S to re-build the whole signed history.If you want to sign all the existing commits on the branch without do any changes to them:
git rebase --exec 'git commit --amend --no-edit -n -S' -i origin/HEAD