在GitHub上显示二进制文件的文本差异 [英] Display text diffs for binary files on GitHub

查看:101
本文介绍了在GitHub上显示二进制文件的文本差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Git和GitHub同步许多应用程序配置文件.这些是以二进制格式存储的XML或plist文件.例如,一个键盘大师 .kmsync 文件.

I'm trying to use Git and GitHub to sync a number of app configuration files. These are XML or plist files stored in a binary format. For example, a Keyboard Maestro .kmsync file.

我可以通过文本编辑器打开这些文件以查看XML格式.

I can open these files via a text editor to see an XML format.

但是当我在GitHub Pull Request,commit视图等中查看这些文件差异时,我看到了无用的二进制差异,没有可见的变化:

But when I view these file diffs in a GitHub Pull Request, commit view, etc. I see a useless binary diff with no visible changes:

显示0个添加项和0个删除项.
BIN +17字节(100%)
二进制文件未显示.

Showing with 0 additions and 0 deletions.
BIN +17 Bytes (100%)
Binary file not shown.

我可以通过 .gitattributes 文件通过git在本地显示基于文本的差异.但是,似乎GitHub不尊重这些修改:

I can get the a text-based diff to display locally via git via a .gitattributes file. However, it appears that GitHub doesn't respect these modifications:

GitHub不使用.gitattributes文件来选择要在差异中显示的文件,因此无法以这种方式解决. [源代码]

当我在commit和Pull Requests中在GitHub上查看这些文件时,我想查看基于文本的更改和行差异.

I want to see the text-based changes and line diffs when I view these files on GitHub in my commits and Pull Requests.

例如,此处的GitHub PR.随意进行分叉和实验:
https://github.com/pkamb/so/pull/1

For example, the GitHub PR here. Feel free to fork and experiment:
https://github.com/pkamb/so/pull/1

我如何说服 GitHub存储库的网络视图对某些二进制"内容使用基于文本的差异.文件?

How can I convince the web view of a GitHub repo to use text-based diffing for certain "binary" files?

我找不到针对特定问题的现有问题(在GitHub上显示非二进制差异 ).

I cannot find an existing question for my specific ask (displaying a non-binary diff on GitHub).

以下问题与这种行为有关,但与本地 git (不是GitHub)有关.

The following questions relate to for this same behavior, but for local git (not GitHub).

我的问题是这个问题的相反,该问题试图将文本文件显示为GitHub上的二进制文件:

My question is the opposite of this question, which seeks to display text files as binary files on GitHub:

推荐答案

无法强制GitHub将这些文件显示为文本,因为它们不是.当GitHub将文件呈现为HTML页面的一部分时,它们必须采用某种编码方式,而如今编码的唯一合理选择是UTF-8.这些文件不能包含UTF-8格式的字节序列,而且不能包含UTF-8格式的字符,此外,控制字符通常不能在网页中很好地呈现.

There isn't a way to force GitHub to display these files as text because they are not. When GitHub renders files as part of an HTML page, they must be in some encoding, and the only reasonable choice for encodings these days is UTF-8. These files cannot be displayed as-is as UTF-8 because they contain byte sequences that are not valid in UTF-8, in addition to control characters, which generally cannot be rendered well in a web page.

可以使用 diff 类型和 diff.*.textconv .gitattributes 文件将这些文件转换为文本以进行比较.>配置文件中的属性.这在您的机器上很好用,但是在GitHub上不起作用.首先,GitHub没有提供用于呈现文件的工具,其次,GitHub总体上不支持用于呈现文件的外部程序,主要是出于安全原因.支持某些常用格式,但这不是其中一种.

It is possible to convert these files to text for diffing using a .gitattributes file using the diff type and the diff.*.textconv attribute in your config file. This works great on your machine, but it won't work on GitHub. First of all, GitHub doesn't have your tool for rendering files, and secondly, GitHub doesn't support external programs for rendering files in general, mostly for security reasons. Some common formats are supported, but this is not one of them.

还请注意,要使用的程序存储在Git配置中,而不存储在 .gitattributes 文件中;这是有意的,因为传送要在存储库中执行的程序列表是一个安全问题.因此,GitHub甚至不可能知道您将在此处使用的程序.

Also note that the program to be used is stored in the Git configuration and not in the .gitattributes file; this is intentional, since shipping a list of programs to execute in the repository is a security problem. Therefore, GitHub can't possibly even know the program you'd be using here.

如果您的 kmsync 文件具有等效的纯文本格式,您可以将其编译为二进制格式,则可以将该格式存储在存储库中,并将其作为构建步骤的一部分进行构建.这将是可变化的,并且仍将提供可用于项目的二进制格式.这与将代码编译成二进制文件或将纯文本编译成PDF没什么不同.

If your kmsync files have a plain text equivalent that you can compile into the binary format, then you can store that format in the repository and build it as part of a build step. That will be diffable and will still provide the binary formats that you can use for your project. This is no different than compiling code into binaries or plain text into PDFs.

这篇关于在GitHub上显示二进制文件的文本差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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