One of the areas where GitHub copilot has really accelerated my development process is in the crafting of commit messages. It does a great job at determining and explaining the changes saves quite a bit of typing. If you commit frequently this can be a big time savings!
However, the out-of-box commit messages may not match the standard structure or formatting on your team. Fortunately there is a new experimental setting in VSCode that allows you to provide a custom prompt to the creation of all commit messages:
> github.copilot.chat.commitMessageGeneration.instructions
Team Commit Message Format
On my team we have standardized our pull request and commit message format to help encourage the creation of meaningful explanations for changes. This format has two sections:
- Motivation – This is the driver behind making the change. Why is this change being made and how does it help.
- Modifications – This is a bulleted list of descriptions of changes made to each file.
So how do we customize Copilot to create our commit messages in this format?
The answer is that we can add an entry to our settings.json file that will provide the prompt to do this on the creation of every commit message:
{
"github.copilot.chat.commitMessageGeneration.instructions": [
{
"text":"Add two sections with heading titles of Motivation and
Modifications. Make those two sections Header 1 titles
using markdown. For motivation put the reason for the
commit. For the modifications, add a one sentence
description of each file that has changed as a bulleted
list. Limit each line to 80 characters."
}
]
}
Impact
So how does this impact what Copilot generates for the commit message?
Original Commit Message
Here is the commit message that Copilot generates out-of-the-box for the addition of the settings.json file above: > Add settings for commit message generation instructions
Improved Commit Message
Here is the commit message when it follows the commitMessageGeneration.instructions:
> # Motivation > Enhance commit message generation instructions for better clarity and structure. > > # Modifications > – Updated settings.json to include detailed instructions for commit message generation.
Nice! This new commit message structure is following the settings I added to the settings and now conforms to my team standard.
This can also be done in Visual Studio, but instead of using a settings file you have to do it in the UI settings: Tools->Options->GitHub->Copilot
