1091 1911 1761 1735 1052 1578 1402 1343 1303 1532 1436 1382 1123 1449 1945 1711 1075 1006 1334 1816 1113 1697 1382 1109 1316 1199 1512 1820 1986 1664 1962 1825 1960 1863 1820 1409 1931 1218 1450 1693 1772 1798 1709 1577 1042 1629 1267 1990 1456 1308 1619 1638 1091 1269 1336 1897 1420 1445 1980 1125 1421 1628 1805 1249 1170 1578 1755 1360 1462 1589 1554 1558 1108 1287 1076 1764 1262 1355 1816 1590 1643 1019 1863 1177 1613 1120 1294 1974 1623 1511 1119 1061 1999 1235 1197 1292 1118 1410 1748 Quick Git trick: Sign your commits after the fact | PHPnews.io

PHPnews.io

Quick Git trick: Sign your commits after the fact

Written by Stefan Koopmanschap / Original link on Sep. 14, 2021

OK, so this might be a situation you may get into, but I'm blogging this as much for myself as for others because I know this is a situation that I might also head into:

You start working on a new project for a new customer, and you forget to set up PGP signing of your commits in your Git configuration. Now you've pushed your branch, made a pull request but the pull request can not be merged because your commits are not signed. OH NO! Now what?

The one-liner

Luckily, I'm not the only one to do this and a quick search around the web resulted in this post on superuser.com and look, it is actually quite easy. First of all, you configure git to use your PGP key and set the correct email address. Then you use git log to find out the commit hash of the commit before your first commit. Then you use the command:

git rebase --exec 'git commit --amend --no-edit -n -S' -i <commit hash>

Where, obviously, you replace <commit hash> with the actual commit hash.

Simply write and quit the editor coming up describing what the rebase is going to do, and... TADA! All your commits are now signed.

Force push

Yes, you will have to force push your changes to your branch. But since the merging of the pull request was blocked anyway, no one will have pulled your changes. Right? RIGHT?

If anyone pulled your changes before you force pushed, you'll have to warn them and prepare them for a bit of extra work.

Done!

And that's it. That's all you need to do to sign your commits after the fact. And next time you start working on a new project, don't forget to configure Git to use your key and sign your commits from the start.

skoop

« Cagilo: Blade Components for Laravel - Big New Livewire Release: v2.6.0 »