2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

コミットメッセージをGitHub Copilotに考えてもらう

Posted at

Copilot.vim を使ってCLIからコミットする際に、コミットメッセージを補完してもらう。

基本的には、Copilot.vimGetting startedに記載があるとおりに進める。

1. NeovimかVimか

  1. Install Neovim or the latest patch of Vim (9.0.0185 or newer).

Neovimでいくか、Vimでいくか、お好きな方で。

2. Node.jsのインストール

  1. Install Node.js.

もしインストールしていなければ、Node.jsをインストールする。

3. copilot.vimのインストール

Install github/copilot.vim using vim-plug, packer.nvim, or any other plugin manager. Or to install manually, run one of the following commands:

ご自身の環境に合うインストール方法で。
自分はNeovim, Linux/macOS なので↓

$ git clone https://github.com/github/copilot.vim.git \
  ~/.config/nvim/pack/github/start/copilot.vim

4. GitHub Copilotと連携する

Neovim/Vimを起動して、:Copilot setup
指示に従って連携していく。
Copilot: Authenticated as GitHub user hogehoge って表示されたらOK。
IDEとかで既に連携済みなら、↑が表示されると思う。

5. ファイルタイプの有効化

どうやらデフォルトではコミットメッセージやmarkdown等のファイル形式でのサジェストは無効化されているらしいので、設定ファイルで下記を有効化しておく。

ref. Tips for using Github Copilot in Vim

let g:copilot_filetypes = {
    \ 'gitcommit': v:true,
    \ 'markdown': v:true,
    \ 'yaml': v:true
    \ }

自分は設定ファイルはLuaで記述しているため、init.luaに↓を追記。

init.lua
vim.g.copilot_filetypes = { markdown = true, gitcommit = true, yaml = true }

6. コミットする際はdiffも表示する

コミットメッセージテンプレートにdiffが表示されていた方がサジェストの精度が上がった印象。
コミットする際は、-vオプションを付けてあげた方が良さそう。

これで良い感じにコパ君が補完してくれる。はず。
スクリーンショット 2023-06-16 9.25.04.png

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?