From e6b90e634497f4ac34bbb23c4f01972428c44785 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Wed, 22 May 2024 21:48:29 +0100 Subject: [PATCH] Add daily email for 2024-05-20 Referencing other commits in commit messages --- source/_daily_emails/2024-05-20.md | 44 ++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 source/_daily_emails/2024-05-20.md diff --git a/source/_daily_emails/2024-05-20.md b/source/_daily_emails/2024-05-20.md new file mode 100644 index 000000000..69ac91139 --- /dev/null +++ b/source/_daily_emails/2024-05-20.md @@ -0,0 +1,44 @@ +--- +title: Referencing other commits in commit messages +date: 2024-05-20 +permalink: daily/2024/05/20/referencing-other-commits-in-commit-messages +tags: + - software-development + - git +cta: ~ +snippet: | + Have you tried referencing other commits when writing a commit message? +--- + +Last week, I asked [whether you should include issue IDs in commit messages][0]. + +Another thing I like to reference in a commit message is the commit ID (or SHA) of a related commit. + +For example, when I run `git log` in my website repository, I see commits like this: + +```plain +commit 0c91825c16217d0fe7eff4ea100a67550051c4a9 +Author: Oliver Davies +Date: Sat May 11 15:32:07 2024 +0200 + + Create a cached talk counter + + Create a cached version of the talk counter service that returns a + cached result of the talk count for that day. + + This uses the Decorator design pattern to decorate the existing + `TalkCounter` service and works as they both implement the same + `TalkCounterInterface`. +``` + +The sha for this commit is `0c91825c16217d0fe7eff4ea100a67550051c4a9`. + +If I was to make another commit that was related to this one, I can include this commit sha in my new commit message. + +I also don't need to include the entire thing - only enough for it to be unique (usually five or six characters). + +Once pushed, the commit IDs should never change, so this will be a permanent reference to the first commit. + +Helpfully, websites like GitHub, GitLab and Bitbucket will identify it as a commit sha and make it clickable so you can easily navigate to the referenced commit. + +[0]: {{site.url}}/daily/2024/05/15/should-you-include-issue-ids-in-your-commit-messages