用于元数据存储/检索的 Git 挂钩

发布于 2024-08-22 16:56:10 字数 406 浏览 4 评论 0原文

git 不可避免的怪癖之一是它无法存储和检索有关文件的元数据。例如,在 Mac 上,标签以“扩展属性”存储(可通过 xattr 访问),如果文件受到检出影响,则任何检出/重置/合并/拉取命令都将删除这些属性。

我环顾四周,看看是否有人已经编写了元数据保存脚本,但我一无所获。

所以我想做的是使用 Git 的钩子系统:

  1. 在提交文件时读取扩展属性,
  2. 将属性写入存储在存储库中的文件,该文件也被提交,
  3. 将扩展属性应用于在合并中修改的文件/结账/重置。

我应该使用哪个挂钩? post-receivepre-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:

  1. Read extended attributes when files are committed,
  2. Write the attributes to a file stored in the repository that also gets committed,
  3. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你与清晨阳光 2024-08-29 16:56:10

gibak 工具使用预提交和< code>post-checkout 让其 ometastore 工具保存/恢复元数据(可选地包括 xattrs)。

您不需要接收后。它在推送的远程端运行。它运行于裸存储库,因此它没有必要尝试从推送的提交内容中更新任何文件。在结帐后执行此操作,您知道您将有一个可用的工作树。

The gibak tool uses pre-commit and post-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 in post-checkout where you know you will have a working tree available.

梦屿孤独相伴 2024-08-29 16:56:10

metastore 能够保存和恢复文件元数据,将其存储在单独的文件中(您可以将其包含在您的提交中)

metastore is able to save and restore file metadata, storing it in a separate file (which you can include in your commits)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文