git 和二进制文件的自定义差异

Mic*_*ael 5 git

我有一个二进制文件格式,包含在 git 存储库中。我知道二进制文件的文件格式,并且可以想象为它们创建一个类似 diff 的工具,该工具会生成文本输出,这样当我查看 git 历史记录时我就可以看到差异。我什至可以创建一个工具,可以获取原始二进制文件和差异文本并创建新的二进制文件,这样 git 就不必一遍又一遍地保存二进制文件并进行小的更改。

如果我要制作这些类型的工具,我如何将它与 git 集成?

Mat*_*nry 4

git help config

\n\n
   diff.external\n       If this config variable is set, diff generation is not performed\n       using the internal diff machinery, but using the given command. Can\n       be overridden with the \xe2\x80\x98GIT_EXTERNAL_DIFF\xe2\x80\x99 environment variable.\n       The command is called with parameters as described under "git\n       Diffs" in git(1). Note: if you want to use an external diff program\n       only on a subset of your files, you might want to use\n       gitattributes(5) instead.\n
Run Code Online (Sandbox Code Playgroud)\n\n

gitattributes(5)还提到了一种称为 的机制textconv:您不提供 diff 程序,而是提供一个将二进制文件转换为文本摘要的程序;然后使用正常的 git diff 机制来呈现这些文本摘要的差异。

\n\n

编辑:我不知道有什么方法可以使低级对象打包例程使用自定义差异工具。阅读低级git-pack-objects(1)手册页的字里行间,底层包格式似乎使用二进制差异格式,它自适应地搜索现有对象来构造二进制增量,以避免存储整个新对象。在这个级别上,对象(文件)只是二进制 blob,我认为除了最模糊的情况之外,最好将对象打包内容视为实现细节。

\n\n

换句话说,如果您的二进制对象在二进制级别上彼此相似,那么它们将由 git 自动有效地表示。我能想象的常见情况是压缩和加密文件,但这种情况并非如此。

\n