【问题标题】:Git: Get all notes of a branchGit:获取分支的所有注释
【发布时间】:2013-12-02 09:05:58
【问题描述】:

我们想用git notes add 注释我们的提交,这很好用。要获取带有注释的所有提交的列表,我们使用此命令

git notes | cut -d' ' -f2 | xargs -ihash git log hash -1

现在我们只寻找一个分支的注释。我在这里不知所措,因为笔记对分支一无所知。可能有一种方法可以从git log 开始并询问git notes 是否有提交注释。但是我很确定这对于大型存储库来说是否会变慢。

有什么想法吗?

【问题讨论】:

  • 我看到你在你的命令中使用'git log',根据这个答案:stackoverflow.com/questions/4649356/…,也许(我不确定)如果你在之后添加你的分支??例如:'git log mybranch' ??

标签: git git-notes


【解决方案1】:

我会从这个开始:

git log --pretty=format:"%H %N" --show-notes <branch>

请参阅git help log 了解您可以在格式字符串中添加的其他内容,以按照您想要的方式修复输出...

【讨论】:

    【解决方案2】:

    发现笔记

    在 master 上显示所有带有注释的缩写提交:

    git notes |\ 
      awk '{if (!system("git merge-base --is-ancestor "$2" master")) {print $2}}' |\
      xargs git show --abbrev-commit --oneline -s --notes
    

    它是如何工作的?

    git notes 列出了笔记 blob 到目标提交的映射:

    $ git notes 
    579c5b129af5662ca2ae6d08977fd5acfe4ca383 3c4f076572612726808d686d04acb2266401c2f9
    63a79274ee3486213d58eef8a5a6f604f7c1fdb1 6546d605b21bb92f270af61f3cc00ff2978001e2
    

    因此您可以通过测试每个提交的分支成员资格来过滤流中的提交。

    但如果你有很多笔记,所有这些单独命令的成本真的会加起来。

    每个分支的注释

    将来您可能想要在这里做的是为不同的分支使用不同的注释引用。我没有看到将core.notesRef 配置选项绑定到当前分支的方法,所以你必须

    git notes --ref "my-branch-name" --edit
    

    等等。但你可能会

    alias gn git notes --ref "$(git rev-parse --abbrev-ref HEAD)"
    

    解决这个问题。

    这不会按分支对您的当前笔记进行排序,但将来会有所帮助。

    您需要为每个配置 refs/notes/branchname" branchname 被提取和推送,如果你想分享的话。

    【讨论】:

      猜你喜欢
      • 2019-11-02
      • 2014-03-28
      • 2014-08-04
      • 2020-05-14
      • 2014-11-02
      • 1970-01-01
      • 2012-07-22
      • 2016-03-01
      • 1970-01-01
      相关资源
      最近更新 更多