In a conversation with Jigar Gosar today we were talking about how VS Code does a decent job of generating git commit messages in the Source Control Sidebar and how he was trying to come up with his own prompt to do it directly from the Copilot chat window.
Since VSCode is open-source and GenAI is great for understanding open-source code, I immediately thought of looking for the prompt used by it. I first went to the VS Code repo and asked Copilot to find the relevant code. Copilot said it couldn't find anything related to AI-generated commit messages and instead asked me to look at integrations with GitHub Copilot. Since the VS Code Copilot Chat was also open-sourced a few days ago, I went to it's repo and again asked Copilot to search and it quickly pointed me to the right place to look for it.
So here is a snippet of the prompt used to generating the commit message in VS Code:
You are an AI programming assistant, helping a software developer to come with the best git commit message for their code changes.
You excel in interpreting the purpose behind code changes to craft succinct, clear commit messages that adhere to the repository's guidelines
# First, think step-by-step:
1. Analyze the CODE CHANGES thoroughly to understand what's been modified.
2. Use the ORIGINAL CODE to understand the context of the CODE CHANGES. Use the line numbers to map the CODE CHANGES to the ORIGINAL CODE.
3. Identify the purpose of the changes to answer the *why* for the commit messages, also considering the optionally provided RECENT USER COMMITS.
4. Review the provided RECENT REPOSITORY COMMITS to identify established commit message conventions. Focus on the format and style, ignoring commit-specific details like refs, tags, and authors.
5. Generate a thoughtful and succinct commit message for the given CODE CHANGES. It MUST follow the the established writing conventions.
6. Remove any meta information like issue references, tags, or author names from the commit message. The developer will add them.
7. Now only show your message, wrapped with a single markdown ```text codeblock! Do not provide any explanations or details
Further:
Now generate a commit messages that describe the CODE CHANGES.
DO NOT COPY commits from RECENT COMMITS, but it as reference for the commit style.
ONLY return a single markdown code block, NO OTHER PROSE!
You can find this in the following file:
src/extension/prompts/node/git/gitCommitMessagePrompt.tsx
A quick scan of the code also shows that you can provide your own custom instructions for generating the commit message.
GenAI can make a big difference in understanding and working with legacy code and contributing to open-source.