用GitLens和Copilot自动生成commit message

Post created: Thu, 14 Nov 2024 21:00:00 +0800

背景

最近我发现了GitLensGitHub Copilot集成的一个特别好用的小功能,就是无需手动输入,就能直接使用 o1-previewo1-mini 模型自动生成提交(commit)消息。

等等,GitHub Copilot不早就有了吗?

Figure: Already exists?

确实,Copilot本身就自带了自动生成commit信息的功能嘛。可是实际用下来发现,这个自带功能默认调用的似乎是GPT-4o模型(出处:trust me bro😜),目前好像也并没有提供让用户自行更改模型的选项。如果你也想选用一些更先进的模型(比如来自OpenAI的o1系列),可以跟着我这个指南走一遍。(如果后面官方确实有了方法,请记得提醒一下我!🙋)

使用步骤如下:

  1. 首先安装GitLens扩展以及GitHub Copilot扩展

    更新(2024年11月20日):安装GitLens后,还需启用Pre-release版本,才能正常与Copilot扩展联动使用。

    Pre-release version of GitLens

  2. 接下来,就愉快地写几行代码吧,随便做些修改。
  3. 进入Source Control页面(快捷键Ctrl+Shift+G,然后再按个G),将鼠标移到SOURCE CONTROL标题右侧,点击出现的三个点的图标(More Actions...)。
  4. 点击”Generate Commit Messages (GitLens)”。

    Generate Commit Messages (GitLens)

  5. 接着,你就可以选择你喜欢的AI模型啦。

    Choose a model

  6. 不过提醒一下哟,用o1系列的模型生成commit message,那等待时间是真的略长,需要耐心……

效果展示

下面是用o1-preview给我生成的一条commit消息:

Add guide on generating commit messages with GitLens

  • Introduce a blog post explaining how to use GitLens and GitHub Copilot to automatically generate commit messages without typing.
  • Include screenshots and update CSS to enhance image display.
  • Organize image assets and update references for better structure.

效果嘛,说实话,还挺到位!自动帮我梳理好了主要做了啥修改,清晰明了,一点也不拖泥带水。

English