Skip to content

Commit 65a654b

Browse files
committed
adding notes around retrospectively signing commits
1 parent fc57a17 commit 65a654b

8 files changed

+79
-0
lines changed

images/commit-history-github.png

60 KB
Loading
10.7 KB
Loading
8.34 KB
Loading
8.45 KB
Loading
26 KB
Loading
32.5 KB
Loading

practices/guides/commit-signing.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,5 @@ git push
179179
Re-run your git command prefixed with GIT_TRACE=1
180180

181181
A failure to sign a commit is usually because the name or email does not quite match those which were used to generate the GPG key, so git cannot auto-select a key. Ensure that these are indeed consistent. (If you added a comment when creating your gpg key, this *may* cause a mismatch: the comment will be visible when listing your gpg keys, e.g. `RealName (Comment) <EmailAddress>`.) You are able to [force a choice of signing key](https://docs.github.com/en/authentication/managing-commit-signature-verification/telling-git-about-your-signing-key), though this should not be necessary.
182+
183+
If you have already committed and need to retrospectively sign this commit [please follow the instructions here](./retrospective-commit-signing.md).
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Retrospective commit signing guide
2+
3+
- [Retrospective commit signing guide](#retrospective-commit-signing-guide)
4+
- [From Workstations](#from-workstations)
5+
- [Troubleshooting](#troubleshooting)
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+
![Commit history showing unsigned and signed commits](../../images/commit-history-github.png)
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+
![Merging is blocked as the commits aren't signed](../../images/merging-is-blocked-signatures.png)
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+
![Interactive rebase before selecting commits](../../images/interactive-rebase-before-selecting-commits.png)
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+
![Interactive rebase after selecting commits](../../images/interactive-rebase-after-selecting-commits.png)
43+
44+
Save the changes by pressing `Ctrl+X`, then press `Enter` to confirm.
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+
![Cycling through commits flagged for editing](../../images/cycle-through-flagged-commits.png)
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+
```
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+
![Updated commit history in GitHub](../../images/updated-commit-history-github.png)

0 commit comments

Comments
 (0)