用于元数据存储/检索的 Git 挂钩
git 不可避免的怪癖之一是它无法存储和检索有关文件的元数据。例如,在 Mac 上,标签以“扩展属性”存储(可通过 xattr 访问),如果文件受到检出影响,则任何检出/重置/合并/拉取命令都将删除这些属性。
我环顾四周,看看是否有人已经编写了元数据保存脚本,但我一无所获。
所以我想做的是使用 Git 的钩子系统:
- 在提交文件时读取扩展属性,
- 将属性写入存储在存储库中的文件,该文件也被提交,
- 将扩展属性应用于在合并中修改的文件/结账/重置。
我应该使用哪个挂钩? post-receive
和 pre-commit
是我所需要的吗? 预提交
还可以将文件添加到提交中(即在写入新属性之后)吗?
One of git's unavoidable quirks is its inability to store and retrieve metadata about a file. For example, on the mac, labels are stored with "extended attributes" (accessible with xattr
), and any checkout/reset/merge/pull command will erase those attributes if the file is affected by the checkout.
I've looked around to see if someone has written metadata-saving scripts already, but I came up dry.
So what I'd like to do is use Git's hook system to:
- Read extended attributes when files are committed,
- Write the attributes to a file stored in the repository that also gets committed,
- Apply the extended attributes to files that are modified in a merge/checkout/reset.
Which of the hooks should I use? Are post-receive
and pre-commit
all that I need? Can pre-commit
also add a file to the commit (i.e., after writing the new attributes)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
gibak 工具使用
预提交
和< code>post-checkout 让其 ometastore 工具保存/恢复元数据(可选地包括 xattrs)。您不需要
接收后
。它在推送的远程端运行。它运行于裸存储库,因此它没有必要尝试从推送的提交内容中更新任何文件。在结帐后
执行此操作,您知道您将有一个可用的工作树。The gibak tool uses
pre-commit
andpost-checkout
to let its ometastore tool save/restore metadata (optionally including xattrs).You do not want
post-receive
. It is run on the remote end of pushes. It runs for bare repositories, so it has no business trying to update any files from the contents of a pushed commit. Do it inpost-checkout
where you know you will have a working tree available.metastore
能够保存和恢复文件元数据,将其存储在单独的文件中(您可以将其包含在您的提交中)metastore
is able to save and restore file metadata, storing it in a separate file (which you can include in your commits)