Git钩住元数据存储/检索 [英] Git hooks for metadata storage/retrieval

查看:112
本文介绍了Git钩住元数据存储/检索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

git的一个不可避免的怪癖是它无法存储和检索关于文件的元数据。例如,在Mac上,标签以扩展属性存储(可通过 xattr 访问),并且任何checkout / reset / merge / pull命令将删除这些属性文件受到结帐的影响。



我查看过是否有人已经编写了元数据保存脚本,但是我干了。 b
$ b

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


  1. 阅读扩展属性当提交文件时,

  2. 将属性写入存储在存储库中的文件中,该文件也将被提交,

  3. 将扩展属性应用于文件在合并/结帐/重置中修改。

我应该使用哪个钩子?是 post-receive pre-commit 所有我需要的?可以 pre-commit 也向提交中添加一个文件(即在写入新属性之后)?

解决方案

gibak 工具使用 pre-commit 结账后让它的 ometastore 工具保存/恢复元数据xattrs)。



你不需要 post-receive 。它在推送的远端运行。它运行于裸存储库,所以它没有任何业务试图从推送提交的内容中更新任何文件。在后结帐中执行,您知道您将有可用的工作树。


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)?

解决方案

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.

这篇关于Git钩住元数据存储/检索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆