将Git注释添加到Blob

7
我正在尝试使用git实现一个用例。
用例: 应该可以向git艺术品添加元数据(如属性)。
我们计划为每个组件设置一个git存储库,因此可以通过为每个提交对象应用注释来实现此要求。
现在,还需要为组件内的文件(在这种情况下是git仓库)提供元数据。为此,我尝试将注释附加到提交的blob中。
它接受了注释,甚至我能够将注释推送到中央仓库。
对于这种用例,使用git注释是否安全可靠?
1个回答

9

2012年:是的,您可以这样使用git笔记

来自Alex Blewitt的博客文章“Git每周提示:Git笔记”提醒我们一些git笔记的优点和注意事项:

注释不一定是文本形式,也不必是可合并的内容。它们甚至不需要在notes/commits引用中;您可以基于任何引用创建注释。
实际上,这就是Gerrit的工作方式(我之前写过)。Gerrit将其审查信息存储在Git存储库中的notes/review下。通常情况下,这不会显示出来(git日志仅在notes/commits refspace中显示注释)
Git Notes实际上是存储在存储库的一个单独的“分支”(存储在.git/refs/notes中)。
合并:由于注释文件本质上是独立的分支,因此内容不会与分支之间的合并合并。如果要合并git notes,则按照单独行上的Key: Value的方式是实现git note合并极乐世界的方法。

"笔记给自己的文章"还指出推送/拉取笔记并不容易。

除了这两个问题(合并和推送),在使用 'git notes' 时,您应该没有问题。


注意:在使用Git 2.39(2022年第四季度)创建新注释时,请避免模板中出现杂散的空白行。

参见提交3c9b01f(由Michael J Gruber (mjg)于2022年11月16日提交)。
(由Junio C Hamano -- gitster --提交2fe427e中合并,时间为2022年11月23日)

笔记:避免模板中的空行

签名:Michael J Gruber
签名:Taylor Blau

When git notes(man) prepares the template it adds an empty newline between the comment header and the content:


#
# Write/edit the notes for the following object:

# commit 0f3c55d
# etc

This is wrong structurally because that newline is part of the comment, too, and thus should be commented.
Also, it throws off some positioning strategies of editors and plugins, and it differs from how we do commit templates.

Change this to follow the standard set by git commit(man):


#
# Write/edit the notes for the following object:

# commit 0f3c55d

Tests pass unchanged after this code change.


所有progit.org的链接都已失效。 - Anton Strogonoff
1
@AntonStrogonoff 感谢您的反馈。我已经修复了这个10年前的答案中所有失效的链接。 - VonC
谢谢!我在想是否值得在元数据上提出有关自动使用存档链接的问题... - Anton Strogonoff
这个问题(以及你的答案)在适用性方面几乎是常青的,因为与现代堆栈的其他部分不同,Git并不每周都在变化 ;) - Anton Strogonoff
@AntonStrogonoff,“web.archive.org”这个话题以前已经被提出过,包括在meta.stackexchange上。 - VonC
很高兴知道在这个想法上我不是孤独的。 - Anton Strogonoff

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接