SlideShare a Scribd company logo
1 of 25
How to write a git commit
message
2018, Miroslav Merinsky
miroslav.merinsky@gmail.com
Why it is so important?
The well-crafted git commit message is the best way to communicate context
about a change to fellow developers. A diff will tell you what changed, but only the
commit message can properly tell you why.
“Re-establishing the context of a piece of code is wasteful. We can’t avoid it completely, so our
efforts should go to reducing it as much as possible. Commit messages can do exactly that and as
a result, a commit message shows whether a developer is a good collaborator.”
Peter
Hutterer
How a commit message should look like?
$ git log
commit 42e769bdf4894310333942ffc5a15151222a87be
Author: Miroslav Merinsky <miroslav.merinsky@gmail.com>
Date: Fri Jan 01 00:00:00 2018 -0200
Subject - summarize changes; 50 characters or less; capitalize; no period; use imperative
Explanation - more detailed explanation text, if necessary; 72 characters
List
- list item I
- list item II
Resolves: #20147
Explanation
Focus on why you are making this change as opposed to how (in meaning source
code changes).
Describe what original problem is.
Do not assume the code is self-evident/self-documenting.
Describe any limitations of the current code.
Side effects or other unintuitive consequences?
Commit content
Only one logical change
- quicker and easier to review and identify potential flaws
- easier troubleshooting
Avoid mixing whitespace changes with functional code changes
Avoid mixing two unrelated functional changes
Avoid sending large new features in a single giant commit
- a new feature often entail refactoring existing code - any refactoring is done in
commits which are separate from those implementing the new feature
- newly written code can often be split up into multiple pieces
Example #1
$ git log
commit 42ffc5a15151222a87be42e769bdf48943103339
Author: John Dow <john.dow@gmail.com>
Date: Fri Jan 01 00:00:00 2018 -0200
Fix typo in introduction to user guide
Example #1 - explanation
$ git log
commit 42ffc5a1515122245545414a87be42e7...
Author: John Dow <john.dow@gmail.com>
Date: Fri Jan 01 00:00:00 2018 -0200
Fix typo in introduction to user guide
Not every commit requires both a
subject and a body.
Sometimes a single line is fine,
especially when the change is so
simple that no further context is
necessary.
Example #2
$ git log
commit a87be42e769bd42ffc5a15151222f48943103339
Author: John Dow <john.dow@gmail.com>
Date: Fri Jan 22 00:00:00 2017 -0200
more fixes for broken stuff
Example #2 - explanation
$ git log
commit a87be42e769bd42ffc5a15151222f4...
Author: John Dow <john.dow@gmail.com>
Date: Fri Jan 22 00:00:00 2017 -0200
more fixes for broken stuff
The first subject letter should be
capital.
An imperative not used.
The “more fixes” evokes that there is
more than one logical change.
Example #3
$ git log
commit a87be42e769bd42ffc5a15151222f48943103339
Author: John Dow <john.dow@gmail.com>
Date: Fri Jan 22 00:00:00 2017 -0200
Fix missing import in compute/utils.py
Fixes bug 1014829
Example #3 - explanation
$ git log
commit a87be42e769bd42ffc5a15151222f4...
Author: John Dow <john.dow@gmail.com>
Date: Fri Jan 22 00:00:00 2017 -0200
Fix missing import in compute/utils.py
Fixes bug 1014829
Unclear. This does not mention what
imports, where it is missing and why it
is needed.
Example #3 - corrected
$ git log
commit a87be42e769bd42ffc5a15151222f48943103339
Author: John Dow <john.dow@gmail.com>
Date: Fri Jan 22 00:00:00 2017 -0200
Add missing import of 'exception' in compute/utils.py
The compute/utils.py makes a reference to exception.NotFound,
however exception has not been imported.
Fixes bug 1014829
Example #4
$ git log
commit a87be42e769bd42ffc5a15151222f48943103339
Author: John Dow <john.dow@gmail.com>
Date: Fri Jan 22 00:00:00 2017 -0200
Present correct ec2id format for volumes and snaps
Fixes bug #1013765
Change-Id: I5e574f8e60d091ef8862ad814e2c8ab993daa366
Example #4 - explanation
$ git log
commit a87be42e769bd42ffc5a15151222f4...
Author: John Dow <john.dow@gmail.com>
Date: Fri Jan 22 00:00:00 2017 -0200
Present correct ec2id format for volumes
and snaps
Fixes bug #1013765
Change-Id:
I5e574f8e60d091ef8862ad814e2c8ab993daa366
This does not mention what the current
(broken) format is, nor what the new
fixed format is.
Example #4 - corrected
$ git log
commit a87be42e769bd42ffc5a15151222f48943103339
Author: John Dow <john.dow@gmail.com>
Date: Fri Jan 22 00:00:00 2017 -0200
Present correct ec2id format for volumes and snaps
During the volume uuid migration, done by changeset 784444,
ec2 id formats for volumes and snapshots was dropped and is
now using the default instance format (i-xb5). These need
to be changed back to vol-xb5 and snap-xb5.
Fixes bug #1013765
Change-Id: I5e574f8e60d091ef8862ad814e2c8ab993daa366
Example #5
$ git log
commit a87be42e769bd42ffc5a15151222f48943103339
Author: John Dow <john.dow@gmail.com>
Date: Fri Jan 22 00:00:00 2017 -0200
Add libvirt min version check
Fixes LP Bug #1012689
Example #5 - explanation
$ git log
commit a87be42e769bd42ffc5a15151222f4...
Author: John Dow <john.dow@gmail.com>
Date: Fri Jan 22 00:00:00 2017 -0200
Add libvirt min version check
Fixes LP Bug #1012689
This commit message is merely
documenting what was done, and not
why it was done.
Example #5 - corrected
$ git log
commit a87be42e769bd42ffc5a15151222f48943103339
Author: John Dow <john.dow@gmail.com>
Date: Fri Jan 22 00:00:00 2017 -0200
Add libvirt version check, min 0.9.7
The commit 47a41r7 introduced use of the 'reset' API
which is only available in libvirt 0.9.7 or newer. Add a check
performed at startup of the compute server against the libvirt
connection version. If the version check fails the compute
service will shutdown.
Fixes LP Bug #1012689
Example #6
$ git log
commit a87be42e769bd42ffc5a15151222f48943103339
Author: John Dow <john.dow@gmail.com>
Date: Fri Jan 22 00:00:00 2017 -0200
Update default policies for KVM guest PIT & RTC timers
The default policies for the KVM guest PIT and RTC timers
are not very good at maintaining reliable time in guest
operating systems. In particular Windows 7 guests will
often crash with the default KVM timer policies, and old
Linux guests will have very bad time drift
Set the PIT such that missed ticks are injected at the
normal rate, ie they are delayed
This corresponds to the following libvirt XML
<clock offset='utc'>
<timer name='pit' tickpolicy='delay'/>
<timer name='rtc' tickpolicy='catchup'/>
</clock>
This should provide a default configuration that works
acceptably for most OS types. In the future this will
likely need to be made configurable per-guest OS type.
Closes-Bug: #1011848
Example #6 - explanation
It describes what the original problem
is (bad KVM defaults)
It describes the functional change
being made (the new PIT policies)
It describes what the result of the
change is (new the XML args)
It describes scope for future
improvement (the possible per-OS
type config)
It uses the Closes-Bug notation
$ git log
commit a87be42e769bd42ffc5a15151222f48943103339
Author: John Dow <john.dow@gmail.com>
Date: Fri Jan 22 00:00:00 2017 -0200
Update default policies for KVM guest PIT & RTC timers
The default policies for the KVM guest PIT and RTC timers
are not very good at maintaining reliable time in guest
operating systems. In particular Windows 7 guests will
often crash with the default KVM timer policies, and old
Linux guests will have very bad time drift
Set the PIT such that missed ticks are injected at the
normal rate, ie they are delayed
This corresponds to the following libvirt XML
<clock offset='utc'>
<timer name='pit' tickpolicy='delay'/>
<timer name='rtc' tickpolicy='catchup'/>
</clock>
This should provide a default configuration that works
acceptably for most OS types. In the future this will
likely need to be made configurable per-guest OS type.
Closes-Bug: #1011848
Example #7
$ git log
commit a87be42e769bd42ffc5a15151222f48943103339
Author: John Dow <john.dow@gmail.com>
Date: Fri Jan 22 05:13:05 2017 -0200
Update default policies for KVM guest PIT & RTC timers
commit 5a15151222f4894a87be42e769bd42ffc5a15489
Author: John Dow <john.dow@gmail.com>
Date: Fri Jan 23 12:08:02 2017 -0200
Add support for configuring libvirt VM clock and timers
Example #7 - explanation
$ git log
commit a87be42e769bd42ffc5a15151222...
Author: John Dow <john.dow@gmail.com>
Date: Fri Jan 22 05:13:05 2017 -0200
Update default policies for KVM guest PIT &
RTC timers
commit 5a15151222f4894a87be42e769bd42...
Author: John Dow <john.dow@gmail.com>
Date: Fri Jan 23 12:08:02 2017 -0200
Add support for configuring libvirt VM
clock and timers
Together these two changes provide
support for configuring the KVM guest
timers.
The introduction of the new APIs for
creating libvirt XML configuration have
been clearly separated from the
change to the KVM guest creation
policy, which uses the new APIs.
Example #8
$ git log
commit a87be42e769bd42ffc5a15151222f48943103339
Author: John Dow <john.dow@gmail.com>
Date: Fri Jan 22 05:13:05 2017 -0200
Refactor libvirt create calls
* minimizes duplicated code for create
* makes wait_for_destroy happen on shutdown instead of undefine
* allows for destruction of an instance while leaving the domain
* uses reset for hard reboot instead of create/destroy
* makes resume_host_state use new methods instead of hard_reboot
* makes rescue/unrescue not use hard reboot to recreate domain
Change-Id: I2072f93ad6c889d534b04009671147af653048e7
Example #8 - explanation
$ git log
commit a87be42e769bd42ffc5a15151222...
Author: John Dow <john.dow@gmail.com>
Date: Fri Jan 22 05:13:05 2017 -0200
Refactor libvirt create calls
* minimizes duplicated code for create
* makes wait_for_destroy happen on
shutdown instead of undefine
* allows for destruction of an instance
while leaving the domain
* uses reset for hard reboot instead of
create/destroy
* makes resume_host_state use new methods
instead of hard_reboot
* makes rescue/unrescue not use hard
reboot to recreate domain
Change-Id:
I2072f93ad6c889d534b04009671147af653048e7
There are at least two independent
changes made in this commit.
There is no compelling reason why
these changes needed to be made at
the same time and clear description
why.
Thank you

More Related Content

Similar to How to write a git commit message

Continuously Integrating Distributed Code at Netflix
Continuously Integrating Distributed Code at NetflixContinuously Integrating Distributed Code at Netflix
Continuously Integrating Distributed Code at NetflixAtlassian
 
Continuous Delivery and Automated Operations on k8s with keptn
Continuous Delivery and Automated Operations on k8s with keptnContinuous Delivery and Automated Operations on k8s with keptn
Continuous Delivery and Automated Operations on k8s with keptnAndreas Grabner
 
Keep you GIT history clean
Keep you GIT history cleanKeep you GIT history clean
Keep you GIT history cleantomasbro
 
Short Introduction to IPv6
Short Introduction to IPv6Short Introduction to IPv6
Short Introduction to IPv6Martin Schütte
 
Crafting Better Git Commits
Crafting Better Git CommitsCrafting Better Git Commits
Crafting Better Git CommitsBrant Burnett
 
Git from the trenches
Git from the trenchesGit from the trenches
Git from the trenchesNuno Caneco
 
Git workflows automat-it
Git workflows automat-itGit workflows automat-it
Git workflows automat-itAutomat-IT
 
git-commands-cheat-sheet-infopediya-com.pdf
git-commands-cheat-sheet-infopediya-com.pdfgit-commands-cheat-sheet-infopediya-com.pdf
git-commands-cheat-sheet-infopediya-com.pdfmurad khan
 
Comtrade file manipulationver1
Comtrade file manipulationver1Comtrade file manipulationver1
Comtrade file manipulationver1Jay Gosalia
 
Git Acquainted
Git AcquaintedGit Acquainted
Git Acquaintedtylerhunt
 
LAS16-TR03: Upstreaming 201
LAS16-TR03: Upstreaming 201LAS16-TR03: Upstreaming 201
LAS16-TR03: Upstreaming 201Linaro
 
ChronicleMap non-blocking cache for Gerrit v3.3
ChronicleMap non-blocking cache for Gerrit v3.3ChronicleMap non-blocking cache for Gerrit v3.3
ChronicleMap non-blocking cache for Gerrit v3.3Luca Milanesio
 
Checkitmobile advanced git
Checkitmobile advanced gitCheckitmobile advanced git
Checkitmobile advanced gitGerrit Wanderer
 
Migrating a .NET application to Go
Migrating a .NET application to GoMigrating a .NET application to Go
Migrating a .NET application to GoJohn Jeffery
 
GIT in a nutshell
GIT in a nutshellGIT in a nutshell
GIT in a nutshellalignan
 

Similar to How to write a git commit message (20)

Continuously Integrating Distributed Code at Netflix
Continuously Integrating Distributed Code at NetflixContinuously Integrating Distributed Code at Netflix
Continuously Integrating Distributed Code at Netflix
 
Continuous Delivery and Automated Operations on k8s with keptn
Continuous Delivery and Automated Operations on k8s with keptnContinuous Delivery and Automated Operations on k8s with keptn
Continuous Delivery and Automated Operations on k8s with keptn
 
GIT Basics
GIT BasicsGIT Basics
GIT Basics
 
Git vs. Mercurial
Git vs. MercurialGit vs. Mercurial
Git vs. Mercurial
 
Keep you GIT history clean
Keep you GIT history cleanKeep you GIT history clean
Keep you GIT history clean
 
Short Introduction to IPv6
Short Introduction to IPv6Short Introduction to IPv6
Short Introduction to IPv6
 
Crafting Better Git Commits
Crafting Better Git CommitsCrafting Better Git Commits
Crafting Better Git Commits
 
Git from the trenches
Git from the trenchesGit from the trenches
Git from the trenches
 
Git workflows automat-it
Git workflows automat-itGit workflows automat-it
Git workflows automat-it
 
Git and git hub
Git and git hubGit and git hub
Git and git hub
 
git-commands-cheat-sheet-infopediya-com.pdf
git-commands-cheat-sheet-infopediya-com.pdfgit-commands-cheat-sheet-infopediya-com.pdf
git-commands-cheat-sheet-infopediya-com.pdf
 
Comtrade file manipulationver1
Comtrade file manipulationver1Comtrade file manipulationver1
Comtrade file manipulationver1
 
Working with Git
Working with GitWorking with Git
Working with Git
 
Git Acquainted
Git AcquaintedGit Acquainted
Git Acquainted
 
LAS16-TR03: Upstreaming 201
LAS16-TR03: Upstreaming 201LAS16-TR03: Upstreaming 201
LAS16-TR03: Upstreaming 201
 
ChronicleMap non-blocking cache for Gerrit v3.3
ChronicleMap non-blocking cache for Gerrit v3.3ChronicleMap non-blocking cache for Gerrit v3.3
ChronicleMap non-blocking cache for Gerrit v3.3
 
Intro to Git and GitHub
Intro to Git and GitHubIntro to Git and GitHub
Intro to Git and GitHub
 
Checkitmobile advanced git
Checkitmobile advanced gitCheckitmobile advanced git
Checkitmobile advanced git
 
Migrating a .NET application to Go
Migrating a .NET application to GoMigrating a .NET application to Go
Migrating a .NET application to Go
 
GIT in a nutshell
GIT in a nutshellGIT in a nutshell
GIT in a nutshell
 

Recently uploaded

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 

Recently uploaded (20)

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 

How to write a git commit message

  • 1. How to write a git commit message 2018, Miroslav Merinsky miroslav.merinsky@gmail.com
  • 2. Why it is so important? The well-crafted git commit message is the best way to communicate context about a change to fellow developers. A diff will tell you what changed, but only the commit message can properly tell you why. “Re-establishing the context of a piece of code is wasteful. We can’t avoid it completely, so our efforts should go to reducing it as much as possible. Commit messages can do exactly that and as a result, a commit message shows whether a developer is a good collaborator.” Peter Hutterer
  • 3. How a commit message should look like? $ git log commit 42e769bdf4894310333942ffc5a15151222a87be Author: Miroslav Merinsky <miroslav.merinsky@gmail.com> Date: Fri Jan 01 00:00:00 2018 -0200 Subject - summarize changes; 50 characters or less; capitalize; no period; use imperative Explanation - more detailed explanation text, if necessary; 72 characters List - list item I - list item II Resolves: #20147
  • 4. Explanation Focus on why you are making this change as opposed to how (in meaning source code changes). Describe what original problem is. Do not assume the code is self-evident/self-documenting. Describe any limitations of the current code. Side effects or other unintuitive consequences?
  • 5. Commit content Only one logical change - quicker and easier to review and identify potential flaws - easier troubleshooting Avoid mixing whitespace changes with functional code changes Avoid mixing two unrelated functional changes Avoid sending large new features in a single giant commit - a new feature often entail refactoring existing code - any refactoring is done in commits which are separate from those implementing the new feature - newly written code can often be split up into multiple pieces
  • 6. Example #1 $ git log commit 42ffc5a15151222a87be42e769bdf48943103339 Author: John Dow <john.dow@gmail.com> Date: Fri Jan 01 00:00:00 2018 -0200 Fix typo in introduction to user guide
  • 7. Example #1 - explanation $ git log commit 42ffc5a1515122245545414a87be42e7... Author: John Dow <john.dow@gmail.com> Date: Fri Jan 01 00:00:00 2018 -0200 Fix typo in introduction to user guide Not every commit requires both a subject and a body. Sometimes a single line is fine, especially when the change is so simple that no further context is necessary.
  • 8. Example #2 $ git log commit a87be42e769bd42ffc5a15151222f48943103339 Author: John Dow <john.dow@gmail.com> Date: Fri Jan 22 00:00:00 2017 -0200 more fixes for broken stuff
  • 9. Example #2 - explanation $ git log commit a87be42e769bd42ffc5a15151222f4... Author: John Dow <john.dow@gmail.com> Date: Fri Jan 22 00:00:00 2017 -0200 more fixes for broken stuff The first subject letter should be capital. An imperative not used. The “more fixes” evokes that there is more than one logical change.
  • 10. Example #3 $ git log commit a87be42e769bd42ffc5a15151222f48943103339 Author: John Dow <john.dow@gmail.com> Date: Fri Jan 22 00:00:00 2017 -0200 Fix missing import in compute/utils.py Fixes bug 1014829
  • 11. Example #3 - explanation $ git log commit a87be42e769bd42ffc5a15151222f4... Author: John Dow <john.dow@gmail.com> Date: Fri Jan 22 00:00:00 2017 -0200 Fix missing import in compute/utils.py Fixes bug 1014829 Unclear. This does not mention what imports, where it is missing and why it is needed.
  • 12. Example #3 - corrected $ git log commit a87be42e769bd42ffc5a15151222f48943103339 Author: John Dow <john.dow@gmail.com> Date: Fri Jan 22 00:00:00 2017 -0200 Add missing import of 'exception' in compute/utils.py The compute/utils.py makes a reference to exception.NotFound, however exception has not been imported. Fixes bug 1014829
  • 13. Example #4 $ git log commit a87be42e769bd42ffc5a15151222f48943103339 Author: John Dow <john.dow@gmail.com> Date: Fri Jan 22 00:00:00 2017 -0200 Present correct ec2id format for volumes and snaps Fixes bug #1013765 Change-Id: I5e574f8e60d091ef8862ad814e2c8ab993daa366
  • 14. Example #4 - explanation $ git log commit a87be42e769bd42ffc5a15151222f4... Author: John Dow <john.dow@gmail.com> Date: Fri Jan 22 00:00:00 2017 -0200 Present correct ec2id format for volumes and snaps Fixes bug #1013765 Change-Id: I5e574f8e60d091ef8862ad814e2c8ab993daa366 This does not mention what the current (broken) format is, nor what the new fixed format is.
  • 15. Example #4 - corrected $ git log commit a87be42e769bd42ffc5a15151222f48943103339 Author: John Dow <john.dow@gmail.com> Date: Fri Jan 22 00:00:00 2017 -0200 Present correct ec2id format for volumes and snaps During the volume uuid migration, done by changeset 784444, ec2 id formats for volumes and snapshots was dropped and is now using the default instance format (i-xb5). These need to be changed back to vol-xb5 and snap-xb5. Fixes bug #1013765 Change-Id: I5e574f8e60d091ef8862ad814e2c8ab993daa366
  • 16. Example #5 $ git log commit a87be42e769bd42ffc5a15151222f48943103339 Author: John Dow <john.dow@gmail.com> Date: Fri Jan 22 00:00:00 2017 -0200 Add libvirt min version check Fixes LP Bug #1012689
  • 17. Example #5 - explanation $ git log commit a87be42e769bd42ffc5a15151222f4... Author: John Dow <john.dow@gmail.com> Date: Fri Jan 22 00:00:00 2017 -0200 Add libvirt min version check Fixes LP Bug #1012689 This commit message is merely documenting what was done, and not why it was done.
  • 18. Example #5 - corrected $ git log commit a87be42e769bd42ffc5a15151222f48943103339 Author: John Dow <john.dow@gmail.com> Date: Fri Jan 22 00:00:00 2017 -0200 Add libvirt version check, min 0.9.7 The commit 47a41r7 introduced use of the 'reset' API which is only available in libvirt 0.9.7 or newer. Add a check performed at startup of the compute server against the libvirt connection version. If the version check fails the compute service will shutdown. Fixes LP Bug #1012689
  • 19. Example #6 $ git log commit a87be42e769bd42ffc5a15151222f48943103339 Author: John Dow <john.dow@gmail.com> Date: Fri Jan 22 00:00:00 2017 -0200 Update default policies for KVM guest PIT & RTC timers The default policies for the KVM guest PIT and RTC timers are not very good at maintaining reliable time in guest operating systems. In particular Windows 7 guests will often crash with the default KVM timer policies, and old Linux guests will have very bad time drift Set the PIT such that missed ticks are injected at the normal rate, ie they are delayed This corresponds to the following libvirt XML <clock offset='utc'> <timer name='pit' tickpolicy='delay'/> <timer name='rtc' tickpolicy='catchup'/> </clock> This should provide a default configuration that works acceptably for most OS types. In the future this will likely need to be made configurable per-guest OS type. Closes-Bug: #1011848
  • 20. Example #6 - explanation It describes what the original problem is (bad KVM defaults) It describes the functional change being made (the new PIT policies) It describes what the result of the change is (new the XML args) It describes scope for future improvement (the possible per-OS type config) It uses the Closes-Bug notation $ git log commit a87be42e769bd42ffc5a15151222f48943103339 Author: John Dow <john.dow@gmail.com> Date: Fri Jan 22 00:00:00 2017 -0200 Update default policies for KVM guest PIT & RTC timers The default policies for the KVM guest PIT and RTC timers are not very good at maintaining reliable time in guest operating systems. In particular Windows 7 guests will often crash with the default KVM timer policies, and old Linux guests will have very bad time drift Set the PIT such that missed ticks are injected at the normal rate, ie they are delayed This corresponds to the following libvirt XML <clock offset='utc'> <timer name='pit' tickpolicy='delay'/> <timer name='rtc' tickpolicy='catchup'/> </clock> This should provide a default configuration that works acceptably for most OS types. In the future this will likely need to be made configurable per-guest OS type. Closes-Bug: #1011848
  • 21. Example #7 $ git log commit a87be42e769bd42ffc5a15151222f48943103339 Author: John Dow <john.dow@gmail.com> Date: Fri Jan 22 05:13:05 2017 -0200 Update default policies for KVM guest PIT & RTC timers commit 5a15151222f4894a87be42e769bd42ffc5a15489 Author: John Dow <john.dow@gmail.com> Date: Fri Jan 23 12:08:02 2017 -0200 Add support for configuring libvirt VM clock and timers
  • 22. Example #7 - explanation $ git log commit a87be42e769bd42ffc5a15151222... Author: John Dow <john.dow@gmail.com> Date: Fri Jan 22 05:13:05 2017 -0200 Update default policies for KVM guest PIT & RTC timers commit 5a15151222f4894a87be42e769bd42... Author: John Dow <john.dow@gmail.com> Date: Fri Jan 23 12:08:02 2017 -0200 Add support for configuring libvirt VM clock and timers Together these two changes provide support for configuring the KVM guest timers. The introduction of the new APIs for creating libvirt XML configuration have been clearly separated from the change to the KVM guest creation policy, which uses the new APIs.
  • 23. Example #8 $ git log commit a87be42e769bd42ffc5a15151222f48943103339 Author: John Dow <john.dow@gmail.com> Date: Fri Jan 22 05:13:05 2017 -0200 Refactor libvirt create calls * minimizes duplicated code for create * makes wait_for_destroy happen on shutdown instead of undefine * allows for destruction of an instance while leaving the domain * uses reset for hard reboot instead of create/destroy * makes resume_host_state use new methods instead of hard_reboot * makes rescue/unrescue not use hard reboot to recreate domain Change-Id: I2072f93ad6c889d534b04009671147af653048e7
  • 24. Example #8 - explanation $ git log commit a87be42e769bd42ffc5a15151222... Author: John Dow <john.dow@gmail.com> Date: Fri Jan 22 05:13:05 2017 -0200 Refactor libvirt create calls * minimizes duplicated code for create * makes wait_for_destroy happen on shutdown instead of undefine * allows for destruction of an instance while leaving the domain * uses reset for hard reboot instead of create/destroy * makes resume_host_state use new methods instead of hard_reboot * makes rescue/unrescue not use hard reboot to recreate domain Change-Id: I2072f93ad6c889d534b04009671147af653048e7 There are at least two independent changes made in this commit. There is no compelling reason why these changes needed to be made at the same time and clear description why.

Editor's Notes

  1. A good commit tell us about change background - what and why is changed. A good commit means a developer does not need to study source code changes and know the commit purpose. A good commit leads to better effectivity and productivity and leads to efficient using git tools like git blame, revert, rebase, log and shortlog.
  2. Subject Summarize changes as short description why the commit has been done. Limit the subject line to 50 characters. It is not hard limit (72 characters - i.e. GitHub truncates longer), but it is recommended. It keeps subjects readable. Begin subject line with a capital letter. Do not end the subject line with a period. Unnecessary. Use the imperative mood in the subject line. It means giving command or instruction how to do it, i.e. wrap the body at 72 characters; fix typoTip: Good subject line always be able to complete the following sentence: “If applied, this commit will your subject line” Blank line (important) - separator between subject and explanation Explanation Detailed explanation text, if necessary Wrap it to 72 characters (some editors do it automatically, like vim) List - typically a hyphen or asterisk is used for the bullet, preceded by a single space; blank lines in between is possible If you use an issue tracker, put references to them at the bottom
  3. Explain the problem that this commit is solving. Just focus on making clear the reasons why you made the change, describe the intent/motivation behind the changes. the way things worked before the change (and what was wrong with that), the way they work now, and why you decided to solve it the way you did When reading bug reports, after a number of back &amp; forth comments, it is often as clear as mud, what the root cause problem is. The commit message should have a clear statement as to what the original problem is. Do not assume the reviewer understands what the original problem was. Do not assume the reviewer has access to external web services/site. What is self-evident to one person, might be clear as mud to another person. Always document what the original problem was and how it is being fixed, for any change except the most obvious typos, or whitespace only commits. If the code being changed still has future scope for improvements, or any known limitations then mention these in the commit message. This demonstrates to the reviewer that the wide picture has been considered. Are there side effects or other unintuitive consequences of this change?
  4. Only one logical change - important A smaller change leads to quicker and easier review and identify potential flaws Easier troubleshooting - when a flaws are found, it is easier to find and fix them Avoid mixing whitespace changes with functional code changes - the whitespace changes will obscure the important functional changes, making it harder for a reviewer to correctly determine whether the change is correct. Avoid mixing two unrelated functional changes - it is harder to identify flaws if two unrelated changes are mixed together for reviewer &amp; harder troubleshooting later Avoid sending large new features in a single giant commit A new feature often entail refactoring existing code. It is highly desirable that any refactoring is done in commits which are separate from those implementing the new feature. This helps reviewers and test suites validate that the refactoring has no unintentional functional changes. A newly written code can often be split up into multiple pieces - i.e. new public HTTP APIs or RPC interfaces should be done in commits separate from the actual internal implementation
  5. This commit is OK. Use git commit -m “subject” for these commits.
  6. Tip: “If applied, this commit will your subject line” rule. “If applied, this commit will more fixes for broken stuff” does not work.
  7. Again this info was available in the bug tracker and should have been included in the commit message.
  8. It should have mentioned what earlier changeset introduced the new min libvirt version.
  9. Right commit.