Skip to content

Instantly share code, notes, and snippets.

@robertpainsi
Last active December 21, 2024 14:56
Show Gist options
  • Save robertpainsi/b632364184e70900af4ab688decf6f53 to your computer and use it in GitHub Desktop.
Save robertpainsi/b632364184e70900af4ab688decf6f53 to your computer and use it in GitHub Desktop.
Commit message guidelines

Commit Message Guidelines

Short (72 chars or less) summary

More detailed explanatory text. Wrap it to 72 characters. The blank
line separating the summary from the body is critical (unless you omit
the body entirely).

Write your commit message in the imperative: "Fix bug" and not "Fixed
bug" or "Fixes bug." This convention matches up with commit messages
generated by commands like git merge and git revert.

Further paragraphs come after blank lines.

- Bullet points are okay, too.
- Typically a hyphen or asterisk is used for the bullet, followed by a
  single space. Use a hanging indent.

Example for a commit message

Add CPU arch filter scheduler support

In a mixed environment of…

A properly formed git commit subject line should always be able to complete the following sentence

If applied, this commit will <your subject line here>

Rules for a great git commit message style

  • Separate subject from body with a blank line
  • Do not end the subject line with a period
  • Capitalize the subject line and each paragraph
  • Use the imperative mood in the subject line
  • Wrap lines at 72 characters
  • Use the body to explain what and why you have done something. In most cases, you can leave out details about how a change has been made.

Information in commit messages

  • Describe why a change is being made.
  • How does it address the issue?
  • What effects does the patch have?
  • Do not assume the reviewer understands what the original problem was.
  • Do not assume the code is self-evident/self-documenting.
  • Read the commit message to see if it hints at improved code structure.
  • The first commit line is the most important.
  • Describe any limitations of the current code.
  • Do not include patch set-specific comments.

Details for each point and good commit message examples can be found on https://wiki.openstack.org/wiki/GitCommitMessages#Information_in_commit_messages

References in commit messages

If the commit refers to an issue, add this information to the commit message header or body. e.g. the GitHub web platform automatically converts issue ids (e.g. #123) to links referring to the related issue. For issues tracker like Jira there are plugins which also converts Jira tickets, e.g. Jirafy.

In header:

[#123] Refer to GitHub issue…
CAT-123 Refer to Jira ticket with project identifier CAT…

In body:

…
Fixes #123, #124

Sources

@robertpainsi
Copy link
Author

@sorcerykid, http://whatthecommit.com/ (refresh a few times until you find the commit message that suites your changes 😉)

There isn't really an "accepted practice" here. Maybe you still can split your changes into multiple commits?
Leaving following note here:

Commit Often, Perfect Later, Publish Once

@GeorgeGkas
Copy link

I want to propose a possible improvement in References in commit messages section. There are times, not very often but exists, that a commit refers to more than one issue. Most of the times, when this happens, a commit will not refer to more than 2 -maybe 3- issues. To be able to reference multiple issues in the header I propose the following format:

[#123, #879] Refer to GitHub issue…

I would like to read what is your reaction to this update. 😄

@rsp
Copy link

rsp commented Apr 17, 2018

@robertpainsi 👍 Excellent guideline, thanks for sharing that. I would only have one comment that I don't generally recommend putting any references to issues or pull requests into the commit message subjects (first line) because I like them to strictly adhere to the "Do something" style with no information that is not meaningful by itself, especially when viewed outside of GitHub like in the command line, or in the case of moving the project to other git hosting, or forking, in which case the issue/PR numbers will be invalid. For that reason I recommend putting those always in the body of the commit message instead. Other than that I think your guideline is really good and I might add some of your commit message rules to my guideline if you don't mind. 😁

@anxiousinc
Copy link

Thank you so much for the knowledge.

@pkmandke
Copy link

What is the generally accepted practice if a commit contains numerous unrelated changes that cannot be described succinctly in just 50 characters?

For example, if a recent project involves patching a vulnerability in the login handler, removing unused image and sound files, refactoring code and adding better comments, improving performance of the main event loop, fixing bugs in the collision detection algorithm, etc. There is no possible way all of that can fit into a subject line. Yet a generic subject line like "Addressed a lot of lingering issues (see below)" doesn't conform to the conventions described above either.

Any advice would be greatly appreciated. Thanks!

How about splitting the changes into multiple commits if they are so very unrelated? That would not only make your commit messages specific but also keep similar changes together in one commit.

@shoogle
Copy link

shoogle commented Jun 6, 2019

How about splitting the changes into multiple commits if they are so very unrelated?

Agreed! This is the only acceptable way to do it. Some projects ask contributors to squash commits together, but this does not usually apply when the commits contain unrelated changes. In fact, unrelated changes should probably be in a separate pull request, let alone a separate commit.

Aim for atomic commits: each commit should do one thing only. Similarly, a pull request should aim to fix one bug or implement one new feature. It should only contain multiple commits if that is required to fix the bug or implement the feature.

If your commit / pull request title contains the word "and" then you probably should have used two commits / pull requests.

@janus007
Copy link

Aim for atomic commits: each commit should do one thing only. Similarly, a pull request should aim to fix one bug or implement one new feature. It should only contain multiple commits if that is required to fix the bug or implement the feature.

I seems a bit limited, in the wrong way, that a pull request with one feature, only should consist of one commit. I can easily have 8-10 commits to implement a feature.
The idea with commits are to commit often, so you easily can revert and easily see the progress.
I also often do squashes, but more often I merge master into my branch and I push a couple of 3-4 times a day to my own branch.

@shoogle
Copy link

shoogle commented Jun 14, 2019

I seems a bit limited [...] that a pull request with one feature, only should consist of one commit.

It's something to aspire to rather than a strict requirement. What counts as "one feature" is ususally determined by what a user wrote in a single issue in the tracker, but we all know that some features are bigger than others. I said multiple commits are allowed, if necessary.

The most important thing is to ensure that that each commit does exactly one thing: no more, no less. Developers look at commits when they try to understand your code changes. If there are too many commits then the history will be too long, but if there are too few then the diffs will be too long and it will be hard to understand what they do from the summary alone.

The idea with commits are to commit often, so you easily can revert and easily see the progress.

Yes indeed, but that is mainly for when you are working on your own branch, and this guide doesn't really apply in that situation. In fact I would recommend you ignore this guide entirely on your own branch, because writing detailed commit messages is a burden that will discourage you from committing early and often. However, once you have got something working, you need to tidy it up a bit before sharing it with other people. That's where this guide comes in, and tools like --fixup and --autosquash help a lot too.

@denismullaraj
Copy link

What is the generally accepted practice if a commit contains numerous unrelated changes that cannot be described succinctly in just 50 characters?
For example, if a recent project involves patching a vulnerability in the login handler, removing unused image and sound files, refactoring code and adding better comments, improving performance of the main event loop, fixing bugs in the collision detection algorithm, etc. There is no possible way all of that can fit into a subject line. Yet a generic subject line like "Addressed a lot of lingering issues (see below)" doesn't conform to the conventions described above either.
Any advice would be greatly appreciated. Thanks!

How about splitting the changes into multiple commits if they are so very unrelated? That would not only make your commit messages specific but also keep similar changes together in one commit.

👍

@msihera
Copy link

msihera commented Aug 29, 2019

What is the generally accepted practice if a commit contains numerous unrelated changes that cannot be described succinctly in just 50 characters?

@svliantiss
Copy link

How do you do this all in the terminal, specifically referencing issues and other commits?

I'd wish there was a way to stage/pause your commit and use the GitHub interface to comment on it before finishing the push or pull request.

@sharozmirza
Copy link

Does GitHub support markdown in the commit messages?

@jesus2099
Copy link

jesus2099 commented Dec 31, 2019

  1. or reference them
Fetching an object is done by using the technique explained at [1] and…
…
[1] https://www.url.com/some/very/long/url/that/easily/exceeds/72/characters/per/line

We can use the more standard syntax below, so it can be interpreted more likely:

Fetching an object is done by using the technique explained at [cool page] and…
…

[cool page]: https://www.url.com/some/very/long/url/that/easily/exceeds/72/characters/per/line "optional tooltip"
[Official Markdown syntax for links]: https://daringfireball.net/projects/markdown/syntax#link "search reference-style in there"

Put all references in their own paragraph(s) and syntax is [refname]: url (with : a colon).

Result:

Fetching an object is done by using the technique explained at this cool page and…


Official Markdown syntax for links says Reference-style should be:

This is [an example][id] and [another example] [id] or even [id][] reference-style link.
…

[id]: http://example.com/  "Optional Title Here"

But it has been pretty common to just use [id] or [an example] instead of [id][] or [an example][] in the text paragraph.

@ronnielutaro
Copy link

Thank you very much for sharing this knowledge

@NSachida
Copy link

Thanks A Lot 🤗

@Ranjeetkumardev
Copy link

Ranjeetkumardev commented Oct 23, 2020

Can anyone help me plz. When I run a c++ code on vs code then in output section show access is denied . So what issue in my window 10 lp. Thanks a lot $many many whishess for u'r dream in advance

Mail me plz. Ranjeetrazz87654@gmail.com .becoz i'm new here

@NSachida
Copy link

Topics

  • C/C++ for Visual Studio Code

C/C++ support for Visual Studio Code is provided by a Microsoft C/C++ extension to enable cross-platform C and C++ development on Windows, Linux, and macOS.

Getting started

  • C/C++ compiler and debugger

The C/C++ extension does not include a C++ compiler or debugger. You will need to install these tools or use those already installed on your computer.

Popular C++ compilers are:

  • GCC on Linux
  • GCC via Mingw-w64 on Windows
  • Microsoft C++ compiler on Windows
  • Clang for XCode on macOS

"Make sure your compiler executable is in your platform path so the extension can find it." You can check availability of your C++ tools by opening the Integrated Terminal (⌃ (Windows, Linux Ctrl+)) in VS Code and try running the executable (for example g++ --help).
Install the Microsoft C/C++ extension#

Open VS Code.
Click the Extensions view icon on the Sidebar (⇧⌘X (Windows, Linux Ctrl+Shift+X)).
Search for c++.
Click Install.

Hello World tutorials


Get started with C++ and VS Code with Hello
World tutorials for your environment:

  • GCC on Windows
  • Microsoft C++ on Windows
  • GCC on Linux
  • GCC on Windows Subsystem For Linux
  • Clang/LLVM on macOS
Documentation

You can find more documentation on using the Microsoft C/C++ extension under the C++ section, where you'll find topics on:

Debugging
Editing
Settings
FAQ
Remote Development

VS Code and the C++ extension support Remote Development allowing you to work over SSH on a remote machine or VM, inside a Docker container, or in the Windows Subsystem for Linux (WSL).

To install support for Remote Development:

Install the VS Code Remote Development Extension Pack.
If the remote source files are hosted in WSL, use the Remote - WSL extension.
If you are connecting to a remote machine with SSH, use the Remote - SSH extension.
If the remote source files are hosted in a container (for example, Docker), use the Remote - Containers extension.

Feedback

If you run into any issues or have suggestions for the Microsoft C/C++ extension, please file issues and suggestions on GitHub. If you haven't already provided feedback, please take this quick survey to help shape this extension for your needs.

@asapconet
Copy link

Please I'd love to know if there are conventional name tags to give to headings?
For example; 'Fixes, Updates, Feature...'

@CalinZBaenen
Copy link

How do/should I format code in a Git commit message?
Everytime I try using backtick it removes the text (as it's not visible via git log and gone when I do git commit --amend).

Doing git commit --amend is no good, even when I edit the message outside the terminal the text still gets removed for some reason.

Since using backticks won't work, what should I use to format my code?

@CalinZBaenen
Copy link

@Ahmed654321653 What is that, now?

@slnc
Copy link

slnc commented Nov 14, 2022

What is the generally accepted practice if a commit contains numerous unrelated changes that cannot be described succinctly in just 50 characters?

Apply the "Single Responsability Principle" to the commit: split it into smaller logically self-contained commits whose contents can be explained in 50 chars.

I try to stick to that pattern but I sometimes take shortcuts when the cost or splitting is too high or the risk of changing several unrelated things at once is small.

@u-m-i
Copy link

u-m-i commented Aug 25, 2023

Minimalistic approach :

[Action] Short summary (50 chars or less, this is the subject)

(optional) #Issue

More detailed explanatory text, if necessary. Maximun 80 characters to
wrap it.

- Hypen for bullet points.

@kechpaja
Copy link

Use the imperative mood in the subject line

Grammar nitpick: bare infinitive (i.e. "to ", but without the "to"), not imperative. They do look the same, but it's not a command here, it's a description of what will happen when the commit is merged.

@UnitedMarsupials
Copy link

UnitedMarsupials commented Oct 9, 2024

When referencing tickets/issues, I think, the better convention would be to put the references in the body:

Explicitly use Bicycle-class instead of the Vehicle-interface, where applicable

In cases, when bicycle is the only vehicle-type allowed, this simplifies the code
and avoids the redundant casting.

Jira: BOO-11
Bugzilla: 3456

Not only can an organization use multiple ticketing systems in parallel (don't ask), they may also switch from one to another every once in a while.

Putting the tickets into the very summary of the commit does not really help anyone -- the ticket itself is not describing the change...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment