覆盖混帐的选择二进制文件为文本 [英] Override git's choice of binary file to text

查看:220
本文介绍了覆盖混帐的选择二进制文件为文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过的几个问题,询问如何使混帐对待一个文本文件,二进制,但还没有看到相反尚未:

如何修改我的git的选择处理文本文件作为二进制的?我有其中在一些配置字符串的EOT和ETX用于将配置参数的单独的部分的文本文件。

例如,源$ C ​​$ C包含这样几行:

  INPUT 'ScrollRemote[EOT]no[ETX]NumDown[EOT]0[ETX]CalcWidth[EOT]no[ETX]MaxWidth[EOT]80[ETX]FetchOnReposToEnd[EOT]yes[ETX].....'


解决方案

文件的方式,实际存储的Git仓库里面是不相关的,他们是如何显示的时候处理。因此, git的差异程序,当被要求比较两个文件,​​首先获得来自库都完整的文件,然后运行一个差分算法对付他们。

通常情况下, git的差异查找中的文件不可打印的字符,如果它的看起来的类似文件很可能是一个二进制文件,它拒绝以示区别。理据是二进制文件的diff不太可能是人类可读的,可能会弄乱你的终端如果显示的。

不过,您可以指示 git的差异来始终将使用文件为文本 - 文本选项。您可以为一个差异命令来指定这样的:

  git的差异--text头头^ file.txt的

您可以随时混帐通过设立<一使用这个选项href=\"https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html\"><$c$c>.gitattributes文件,其中包含:

  file.txt的差异

这里的差异属性的意思是:


  

差异属性设置为它的路径,将视为文本,即使它们含有通常不会出现在文本文件中,如NULL字节的值。


I've seen several question asking how to make git treat a text file as binary, but haven't seen the opposite yet:

How do I change git's choice of treating a text file as binary? I have a text file where in some configuration strings an EOT and ETX is used to separate parts of the configuration parameters.

For example, the source code contains lines like this:

INPUT 'ScrollRemote[EOT]no[ETX]NumDown[EOT]0[ETX]CalcWidth[EOT]no[ETX]MaxWidth[EOT]80[ETX]FetchOnReposToEnd[EOT]yes[ETX].....'

解决方案

The way files are actually stored inside the Git repository is not relevant to how they are treated when displayed. So the git diff program, when asked to compare two files, first obtains both complete files from the repository and then runs a difference algorithm against them.

Normally, git diff looks for non-printable characters in the files and if it looks like the file is likely to be a binary file, it refuses to show the difference. The rationale for that is binary file diffs are not likely to be human readable and will probably mess up your terminal if displayed.

However, you can instruct git diff to always treat files as text using the --text option. You can specify this for one diff command:

git diff --text HEAD HEAD^ file.txt

You can make Git always use this option by setting up a .gitattributes file that contains:

file.txt diff

The diff attribute here means:

A path to which the diff attribute is set is treated as text, even when they contain byte values that normally never appear in text files, such as NUL.

这篇关于覆盖混帐的选择二进制文件为文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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