AI git commit messages

@hugodemenez

I think you can partially accomplish automatic custom commit messages with a button click using the following:

  • A markdown file describing your commit instructions with a prompt on a repo
  • The doc crawling feature of cursor
  • The @Commit (Diff of Working State or @PR (Diff with Main Branch contexts.

You can even support custom flags of your own. Here is what I do which combines some cool tricks I learned in this forum and the things I figured out by myself after spending quite some time with cursor.

When you wanna commit just use cursor chat to call your commit prompt with the diff context.

@create-commit @Commit (Diff of Working State)

or

git diff | pbcopy in your terminal and than @create-commit <paste-with-command-v> in cursor chat (as mentioned above, there is no context for the staged changes in cursor yet)

If you manage the force the prompt to output the git commit under a markdown codeblock with bash as the language in your prompt(claude-3.5-sonnet seems quite consistent for me as well as figuring out the changes the way I want) than this makes it runnable in yor shell creating a run button, on top right corner.

This may be a little bit overkill for some if you are used to the copilot extension but I find this method quite extendable and practical.

4 Likes

Nice tip ! Thanks for your recommendation, indeed looks good ! As you say a bit overkill ahah

+1 :smiling_face: would be great to have an auto-updating commit message from staged changes without custom prompt/trick needed!

Funny enough, this is exactly what I’ve been doing for the past weeks :slight_smile: I even configured it to give me the “git add” command and to split the diffs into multiple commits if necessary. Now I almost just need to one click “run” :slight_smile:

The only (important) downside : the @gitdiff does not return file removals and file additions… Always double check !

haha nice. how was your experience with the logical splits in commits that your prompt generates?

Yes, until the staged files context is implemented in cursor, it is not always possible to use this method :confused:

This looks similar to my workflow. I tend to stage my files regularly and then look at diff --staged. Really wish cursor would have an option for that as I often find myself doing diff --staged > diff.txt and then using @diff.txt to discuss the changes.

BTW I do this for quite a bit more than just commit comments. I have found that when working with Cursor or other ai coding tools it is super helpful to produce design docs that are designed to provide context for the ai. I use cursor to help me write the docs–often referring to previous commits for context–and then commit them to my repo and use them as the PR context. This allows the LLM prompts to get way more done correctly with fewer unplanned passes.

1 Like

Honestly it works great 99% of the time (appart from the missing staged files context of course).

What could be improved is the prioritization of context. It will sometimes assign a “chore” type with a simple chore task (which is good) but then in the description will include “Created NewComponent in layout” which should be a “feat” commit on it’s own.

Here is what I have added at the end of my prompt template :

You should create different commits if there are multiple changes. Each output should be a valid git commit command. Each output should be a separate executable command. Each output should group changes closely related to each other into a single commit.

Output format (one per commit):

```bash
git add [file1] [file2] ...

git commit -m "<type>[optional scope in lowercase]: <description>

[optional detailed body description]

[optional footer(s)]
"
```_

FYI: the “_” at the end can be removed, it’s only for the quotes to show up in the code snippet :slight_smile:

2 Likes

Have you tried any other extensions for this? I’m using GitLens with Gemini and seems ok: