windows 对于 *.reg 文件,Git 说“二进制文件 a... 和 b... 不同”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5046032/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git says "Binary files a... and b... differ" on for *.reg files
提问by matpie
Is there a way to force Git in to treating .reg
files as text? I am using Git to track my windows registry tweaks and Windows uses .reg
for these files.
有没有办法强制 Git 将.reg
文件视为文本?我正在使用 Git 来跟踪我的 Windows 注册表调整和 Windows.reg
对这些文件的使用。
UPDATE 1:I got it to run a diff (thanks, Andrew). However, now it looks like this below. Is this an encoding issue?
更新 1:我让它运行一个差异(谢谢,安德鲁)。但是,现在看起来像下面这样。这是编码问题吗?
index 0080fe3..fc51807 100644
--- a/Install On Rebuild/4. Registry Tweaks.reg
+++ b/Install On Rebuild/4. Registry Tweaks.reg
@@ -1,49 +1,48 @@
-<FF><FE>W^@i^@n^@d^@o^@w^@s^@ ^@R^@e^@g^@i^@s^@t^@r^@y^@ ^@E^@d^@i^@t^@o^@r^@
-^@;^@;^@;^@;^@;^@;^@;^@;^@;^@;^@;^@;^@;^@;^@;^@;^@;^@;^@;^@;^@;^@;^@;^@;^@;^@;
-^@^M^@
...
Any ideas?
有任何想法吗?
UPDATE 2:Thanks all who helped: here's what I did in the end: create file .gitattributes
with content *.reg text diff
and then I converted the files to UTF-8 as UTF-16 is weird with diffs. I'm not using any foreign characters so UTF-8 works for me.
更新 2:感谢所有提供帮助的人:这是我最后所做的:创建.gitattributes
包含内容*.reg text diff
的文件,然后我将文件转换为 UTF-8,因为 UTF-16 对差异很奇怪。我没有使用任何外来字符,所以 UTF-8 对我有用。
采纳答案by Andrew Marshall
To tell git to explicitly diff a filetype, put the following in a .gitattributes
file in your repository's root directory:
要告诉 git 明确区分文件类型,请将以下内容放入.gitattributes
存储库根目录中的文件中:
*.reg diff
回答by wnoise
Git is treating your registry export files as binary files because they have NULs. There is no good way to diff or merge generalbinary files. A change of one byte can change the interpretation of the rest of the file.
Git 将您的注册表导出文件视为二进制文件,因为它们具有 NUL。没有很好的方法来区分或合并一般的二进制文件。一个字节的改变可以改变对文件其余部分的解释。
There are two general approaches to handling binary files:
有两种处理二进制文件的一般方法:
Accept that they're binary. Diffs aren't going to be meaningful, so don't ask for them. Don't ever merge them, which means only allowing changes on one branch. In this case, this can be made easier by putting each tweak (or set of related tweaks in a separate file, so there's fewer possible ways differences will happen in one file.
Store the changes as text, and convert/deconvert to these binary forms.
接受它们是二进制的。差异不会有任何意义,所以不要要求它们。永远不要合并它们,这意味着只允许在一个分支上进行更改。在这种情况下,通过将每个调整(或一组相关调整放在一个单独的文件中,这样可以减少在一个文件中发生差异的可能方式)。
将更改存储为文本,并转换/解转换为这些二进制形式。
Even though these "text" files, the UTF-16 encoding contains NULs. There appear to be no non-ASCII bits however. Can you convert them to ASCII (or UTF-8, which will be ASCII if there are no extended characters)?
即使这些“文本”文件,UTF-16 编码也包含 NUL。然而,似乎没有非 ASCII 位。您可以将它们转换为 ASCII(或 UTF-8,如果没有扩展字符,它将是 ASCII)吗?
回答by konyak
Convert .reg files from utf16 to utf8 by opening each .reg file in notepad and saving as Encoding UTF-8.
通过在记事本中打开每个 .reg 文件并另存为编码 UTF-8,将 .reg 文件从 utf16 转换为 utf8。
回答by Jonas Bystr?m
Create one utf16toascii.py:
创建一个utf16toascii.py:
#!/usr/bin/env python3
import sys
data = open(sys.argv[-1]).read()
ascii = data.decode('utf-16').encode('ascii', 'replace')
sys.stdout.write(ascii)
Then in bash do:
然后在 bash 中执行:
$ echo "*.reg diff=utf16strings" >> .gitattributes
$ git config --global diff.utf16strings.textconv /path/to/utf16toascii.py
And you're good to diff registry files, as well as Xcode .strings files, or any other utf-16 file.
并且您可以区分注册表文件、Xcode .strings 文件或任何其他 utf-16 文件。