git notes コマンド

Git 基本操作Git 基本操作


git notesこのコマンドにより、ユーザーはコミットに追加ノート(notes)を付けることができます。

ノートはコミットの内容を変更するのではなく、コミットのメタデータに添付されます。レビューコメントや追加説明などの追加情報を記録するのに便利です。

構文

git notes コマンドの基本構文は次のとおりです。

git notes <subcommand> [options] [arguments]
  • <subcommand>:具体的な操作サブコマンド(例:add, show, list, remove, edit, mergeなど)。
  • [options]:コマンドのオプションまたはパラメータ。
  • [arguments]:コマンドの追加パラメータ(コミットハッシュ値など)。

コマンドの使用説明:

  • git notes add:新しいノートをコミットに追加します。

    • -m:ノートの内容を指定します。
    • <commit-hash>:ノートを追加するコミットを指定します(オプション、デフォルトは現在のコミット)。
  • git notes show:コミットのノートを表示します。

    • <commit-hash>:ノートを表示するコミットを指定します(オプション、デフォルトは現在のコミット)。
  • git notes list:現在のブランチ上のすべてのコミットのノートを一覧表示します。

  • git notes remove:コミットのノートを削除します。

    • <commit-hash>:ノートを削除するコミットを指定します(オプション、デフォルトはすべてのノート)。
  • git notes edit:コミットのノートを編集します。 とgit notes add似ていますが、編集モードでデフォルトエディタを開いてノートを編集します。

  • git notes merge:異なるノート記録をマージします。これはマージ時のノートの競合を解決するために使用されます。

  • refs/notes/*:ノートの参照パスを指定するために使用します。ノートをプッシュおよびプルするために使用します。

例

1、ノートを追加

# 添加注释到当前提交
git notes add -m "This commit fixes the login bug"

# 添加注释到特定提交
git notes add -m "Added new feature X" <commit-hash>

2、ノートを表示

# 查看当前提交的注释
git notes show

# 查看特定提交的注释
git notes show <commit-hash>

3、すべてのノートを一覧表示

# 列出当前分支上所有提交的注释
git notes list

4、ノートを削除

# 删除特定提交的注释
git notes remove <commit-hash>

# 删除所有注释(不常用)
git notes remove

5、ノートを編集

# 修改当前提交的注释
git notes edit

6、ノートのプッシュとプル

# 推送注释到远程仓库
git push origin refs/notes/*

# 拉取远程注释
git fetch origin refs/notes/*:refs/notes/*

Git 基本操作Git 基本操作

その他の拡張