|
| 1 | +# Retrospective commit signing guide |
| 2 | + |
| 3 | +- [Retrospective commit signing guide](#retrospective-commit-signing-guide) |
| 4 | + - [Signing previously pushed commits](#signing-previously-pushed-commits) |
| 5 | + - [Steps](#steps) |
| 6 | + |
| 7 | +## Signing previously pushed commits |
| 8 | + |
| 9 | +If you have pushed a commit without signing this can result in your PR not being able to be merged into the main or default branch. The following steps will guide you through retrospectively signing your commits. Note you can sign multiple commits if required. |
| 10 | + |
| 11 | +Please take the time to understand the commands that you are using, this is just a guide. |
| 12 | + |
| 13 | +### Steps |
| 14 | + |
| 15 | +1. **Identify unsigned commits** |
| 16 | + You have a branch that contains one or more unsigned commits. In the screenshot below, there are two unsigned commits followed by two commits showing the `Verified` label, which indicates they were signed. |
| 17 | + |
| 18 | +  |
| 19 | + |
| 20 | +2. **Understand the issue** |
| 21 | + The first two commits aren't verified, and therefore the merge to the `main` branch is not allowed: |
| 22 | + |
| 23 | +  |
| 24 | + |
| 25 | +3. **Switch to the branch with unsigned commits** |
| 26 | + Go to your CLI and ensure that you are on the branch with the unsigned commits. |
| 27 | + |
| 28 | +4. **Start an interactive rebase** |
| 29 | + Issue the following command: |
| 30 | + |
| 31 | + ```bash |
| 32 | + git rebase -i --root |
| 33 | + ``` |
| 34 | + |
| 35 | + This puts the editor into interactive mode for rebase. You will see the commit history as shown in the screenshot below: |
| 36 | + |
| 37 | +  |
| 38 | + |
| 39 | +5. **Mark commits for editing** |
| 40 | + Scroll down the list until you find the commits you want to sign. Change the keyword `pick` to `edit` for those commits. |
| 41 | + |
| 42 | +  |
| 43 | + |
| 44 | + If you are using `Nano`, save the changes with `Ctrl+X` and confirm with `Enter`. For `Vi`, exit with `:wq` to save and quit. |
| 45 | + |
| 46 | +6. **Amend the commit to include a signature** |
| 47 | + For each commit you flagged as `edit`, run the following commands: |
| 48 | + |
| 49 | + ```bash |
| 50 | + git commit -S --amend --no-edit |
| 51 | + git rebase --continue |
| 52 | + ``` |
| 53 | + |
| 54 | + Rebase will cycle through the commits you flagged for editing: |
| 55 | + |
| 56 | +  |
| 57 | + |
| 58 | + Repeat the `amend` and `continue` steps for each commit. |
| 59 | + |
| 60 | +7. **Complete the rebase** |
| 61 | + Once rebasing is complete, you will see a message like: |
| 62 | + |
| 63 | + ```plaintext |
| 64 | + Successfully rebased and updated refs/heads/… |
| 65 | + ``` |
| 66 | + |
| 67 | +8. **Push the changes** |
| 68 | + Push the updated commits back to your branch. Use a force push if necessary: |
| 69 | + |
| 70 | + ```bash |
| 71 | + git push -f |
| 72 | + ``` |
| 73 | + |
| 74 | +9. **Verify the changes** |
| 75 | + Refresh the browser window for your PR. You should now see the verified commits: |
| 76 | + |
| 77 | +  |
0 commit comments