Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

git notes command

git notes command

Git Basic OperationsGit Basic Operations


git notes The command allows users to add additional notes to a commit.

Notes do not modify the content of the commit; instead, they are attached to the commit's metadata, making it convenient to record extra information such as review comments, additional explanations, etc.

Syntax

The basic syntax of the git notes command is as follows:


git notes  [options] [arguments]

Command usage instructions:

- **`-m`**: Specify the content of the note. - **` `**: Specify the commit to add the note to (optional, defaults to the current commit).
  • git notes show: Display the note of a commit.

    • : Specify the commit whose note is to be displayed (optional, defaults to the current commit).
    - **` `**: Specify the commit whose note is to be displayed (optional, defaults to the current commit).
    • git notes list: List notes for all commits on the current branch.

    • git notes remove: Delete the note of a commit.

      • : Specify the commit whose note is to be deleted (optional, defaults to all notes).
      - **` `**: Specify the commit whose note is to be deleted (optional, defaults to all notes).
      • git notes edit: Edit the note of a commit. Similar to git notes add , but opens the default editor in edit mode to edit the note.

      • git notes merge: Merge different note records. This is used to resolve note conflicts during a merge.

      • refs/notes/*: Used to specify the ref path for notes. Used to push and pull notes.

      Example

      1. Add a note

      # 添加注释到当前提交
      git notes add -m "This commit fixes the login bug"
      
      # Add comment to specific commit
      git notes add -m "Added new feature X" 
      

      2. View a note

      # 查看当前提交的注释
      git notes show
      
      # View comments for a specific commit
      git notes show 
      

      3. List all notes

      
      # List all commits on the current branch
      git notes list
      

      4. Delete a note

      
      # Remove comment from specific commit
      git notes remove 
      
      # Delete all comments (rarely used)
      git notes remove
      

      5. Modify a note

      
      # Amend the current commit message
      git notes edit
      

      6. Push and pull notes

      
      # Push comments to remote repository
      git push origin refs/notes/*
      
      # Fetch remote comments
      git fetch origin refs/notes/*:refs/notes/*
      

      Git Basic OperationsGit Basic Operations