【问题标题】:Is git notes the intended way to add category-style information to a commit?git notes 是向提交添加类别样式信息的预期方式吗?
【发布时间】:2011-10-29 09:25:14
【问题描述】:

Can I add metadata to git commits? Or can I hide some tags in gitk 的答案提到 git notes 作为向 git commit 添加元数据的一种方式。

如果我想添加其他类型的注释,git 注释可能会利用其命名空间功能,这是对提交进行分类的最佳方式吗?例如,我想将提交分类为“重构”、“更改功能”、“错误修复”、“错误介绍”,并且能够要求 git 仅列出特定类别中的提交。

【问题讨论】:

    标签: git


    【解决方案1】:

    您的提议与ruby-based gem "step-up" 所做的非常相似,基于git notes

    this Gem 的伟大目标是为开发人员提供一种轻松管理这些笔记的方法。

    通过记录所有相关发展的文化,除了指定要检索的信息类型之外,还可以检索一系列版本的摘要。
    例如,假设您想查看从 v1.10.1 到 v2.0.0 的应用程序中实现的所有功能

    stepup notes --since v1.10.1 upto v2.0.0 --sections pre_deploy pos_deploy
    

    结果将如下所示:

    Showing notes since v1.10.1 up to v2.0.0 (including notes of tags: v1.10.1, v1.10.2, v1.51.0, v2.0.0)
    ---
    Pre-Deploy:
    
      - dependency of version v10 of project XYZ
      - it needed to rename the following file
        - config/environment_variables.yml.sample -> config/environment_variables.yml
      - rake articles:index
    
    Pos-Deploy:
    
      - Reindex articles
        - rake articles:index
      - rake db:seed
      - rake categories:reload
    

    ranged_notes.rb 将根据注释定义获取所有相关提交的函数。
    git.rb 包含实际的git notes 命令。

    【讨论】:

      【解决方案2】:

      我不知道 git-notes(1) 的原作者的意图是什么。但我个人会说不。

      git-notes(1) 用于向提交添加可变元数据。可以肯定的是,如果类别是可变的(例如,您可能想在提交后一段时间添加类别并且您不想更改该提交),那么 git-notes(1) 可能会很有用。但是为什么要使用多个命名空间呢?为什么不将它们存储在一个命名空间下?类别(我想)只是一个关键字,您可以轻松地将简单的字符串附加到注释中。所以你最终可能会得到这样的注释:

      bug fix
      
      breaking change
      
      refactor
      

      做完之后:

      git notes --ref=yourref --append -m 'bug fix'
      git notes --ref=yourref --append -m 'breaking change'
      git notes --ref=yourref --append -m 'refactor'
      

      但是,如果您只需要不可变的元数据(即,您在编写提交时就知道自己想要什么类别),那么只需将类别添加到您的提交消息中就更简单了:

      Big change #4564
      
      Keywords: breaking change, refactor, bugfix
      

      我在这里使用了“关键字”这个名称。

      这可能是一个日志:

      $ git log --patch
      commit 498cc43746aa89a0bb335781eb8157908da12532 (HEAD -> master)
      Author: Victor Version Control <vvc@vcs.org>
      Date:   Fri Sep 24 21:01:47 2021 +0200
      
          Set the scene
      
          Keywords: worldbuilding
      
      diff --git a/novel.md b/novel.md
      index 8bf53766294f..999578522b1f 100644
      --- a/novel.md
      +++ b/novel.md
      @@ -1 +1,4 @@
       Once upon a time there was an ogre.
      +
      +He lived in an ogre village in South-Okranazoa, the highlands west of
      +the lowlands and plains of Kzherbadai.
      
      commit b307a1c02eec479888cba7676e00903071fb0878
      Author: Victor Version Control <vvc@vcs.org>
      Date:   Fri Sep 24 20:59:46 2021 +0200
      
          Start the story
      
          Keywords: intro, ogrekin
      
      diff --git a/novel.md b/novel.md
      new file mode 100644
      index 000000000000..8bf53766294f
      --- /dev/null
      +++ b/novel.md
      @@ -0,0 +1 @@
      +Once upon a time there was an ogre.
      

      如果您想过滤某些关键字的日志,那么您可以使用这个粗略且有些错误的 MVP:

      $ git log --grep='Keywords:.*ogrekin'
      commit b307a1c02eec479888cba7676e00903071fb0878
      Author: Victor Version Control <vvc@vcs.org>
      Date:   Fri Sep 24 20:59:46 2021 +0200
      
          Start the story
      
          Keywords: intro, ogrekin
      

      【讨论】:

        猜你喜欢
        • 2021-02-13
        • 2021-09-24
        • 2017-09-30
        • 1970-01-01
        • 2013-11-02
        • 2018-03-25
        • 2017-03-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多