如何使用 difftool 比较 .odt 文件? kdiff3 diff 输出不可读的字符
How to diff .odt files with difftool? kdiff3 diff outputs unreadable characters
在 git 中,我尝试使用 .gitattributes
来比较 .odt 文件、libreofice 编写器文件和 difftool。
按照本指南:http://www-verimag.imag.fr/~moy/opendocument/ 我制作了一个 .gitattributes
文件 .git 属性:
*.ods diff=odf
*.odt diff=odf
*.odp diff=odf
*.ods difftool=odf
*.odt difftool=odf
*.odp difftool=odf
这使得 git 比较 .odt 中的文本,但是当 git difftool 启动 kdiff3 来比较 .odt 文件时,我得到这个弹出错误:
Some input characters could not be converted to valid unicode.
You might be using the wrong codec. (e.g. UTF-8 for non UTF-8 files).
Don't save the result if unsure. Continue at your own risk.
Affected input files are in A, B.
...文件中的所有字符都是胡言乱语。
出了什么问题?我该如何解决这个问题?
PS:
我不知道这是否重要,但我想我还没有配置 'diff.tool',因为每次我命令:
$ git difftool
我得到这个输出:
This message is displayed because 'diff.tool' is not configured.
See 'git difftool --tool-help' or 'git help config' for more details.
'git difftool' will now attempt to use one of the following tools:
opendiff kdiff3 tkdiff xxdiff meld kompare gvimdiff diffuse diffmerge ecmerge p4merge araxis bc codecompare emerge vimdiff
Viewing (1/1): 'diffexperiment.odt'
Launch 'kdiff3' [Y/n]:
难道这就是 kdiff3 似乎不能与 odt2txt 一起工作的原因吗?
编辑:我重新尝试使用 Microsoft Word 文档执行此操作并取得了更进一步的进展 。
我试过 .kdiff3rc 配置... none 我添加的选项似乎使不可读的字符可读。
我把对比工具改成了vimdiff;当我在 Microsoft Word 文档上执行 git difftool 时,vimdiff 显示了一个以 .xml 结尾的文件列表,而不是不可读的字符。
当我在显示的其中一个文件上按下回车键时:
<?xml version="1.0" encoding="UTF-8"?>
" Browsing zipfile /tmp/4LMJbj_HI I am writing something here..docx |<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Override PartName
" Select a file with cursor and press ENTER |="/_rels/.rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Overr
|ide PartName="/word/settings.xml" ContentType="application/vnd.openxmlformats-officedocument.w
_rels/.rels |ordprocessingml.settings+xml"/><Override PartName="/word/_rels/document.xml.rels" ContentType=
word/settings.xml |"application/vnd.openxmlformats-package.relationships+xml"/><Override PartName="/word/fontTabl
word/_rels/document.xml.rels |e.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+x
word/fontTable.xml |ml"/><Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officed
word/numbering.xml |ocument.wordprocessingml.styles+xml"/><Override PartName="/word/document.xml" ContentType="app
word/styles.xml |lication/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/><Override Part
word/document.xml |Name="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-p
docProps/app.xml |roperties+xml"/><Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlfo
docProps/core.xml |rmats-package.core-properties+xml"/>
[Content_Types].xml |</Types>
我在这个问题上发布了一个新问题 here。
除了 .gitattribute
之外,您还需要 配置 odf
的含义:
git config diff.odf.textconv odt2txt
并且您的 $PATH (Linux/Mac)
或 %PATH%
(Windows) 中需要 odt2txt
(从 OpenDocument 文本到纯文本的简单转换器)。
无需配置difftool
,因为默认kdiff3
就足够了。
但是 kdiff3
需要打开一个文本文件,因此需要 odt2txt
(为了首先将文档转换为文本文件)
有关 textconv
的更多信息,请参阅“Performing text diffs of binary files”:
Sometimes it is desirable to see the diff of a text-converted version of some binary files. For example, a word processor document can be converted to an ASCII text representation, and the diff of the text shown.
Even though this conversion loses some information, the resulting diff is useful for human viewing (but cannot be applied directly).
The textconv
config option is used to define a program for performing such a conversion. The program should take a single argument, the name of a file to convert, and produce the resulting text on stdout.
Note
The text conversion is generally a one-way conversion; This means that diffs generated by textconv
are not suitable for applying.
For this reason, only git diff
and the git log
family of commands (i.e., log
, whatchanged
, show
) will perform text conversion.
git format-patch
will never generate this output.
If you want to send somebody a text-converted diff of a binary file (e.g., because it quickly conveys the changes you have made), you should generate it separately and send it as a comment in addition to the usual binary diff that you might send.
OP Jack mentions :
On Linux I ran in my home directory:
$ git config diff.odf.textconv odt2txt
I had odt2txt
installed... and I assume odt2txt
is in $PATH
, because when I run $ odt2txt
, I get information on odt2txt
.
However, none of those things seem to make git diff .odt
files for some reason.
When I $ git diff fileone.odt filetwo.odt
, I still get the output of Binary files fileone.odt and filetwo.odt differ instead of exactly how the text differentiates.
Not sure why it's not working.
我猜你的情况是 kdiff3
Some input characters could not be converted to valid unicode. You
might be using the wrong codec. (e.g. UTF-8 for non UTF-8 files)....
抱怨是因为它找不到特定字体的特定字符的字形,即它无法绘制它(它们)。
kdiff3 有很多配置选项可以在 ~/.kdiff3rc 配置文件中设置(here 是例子)。我会玩其中一些与编码和字体相关的东西。例如,从更改字体开始,例如
Font=Arial
顺便说一句,当你用你的编辑器打开这些 odt 文件时 - 它是你可读的字体?
PS
也可以在命令行中将选项传递给 kdiff3:kdiff3 --cs "Option1=Val1" --cs "Option2=Val2" --cs ...
在 git 中,我尝试使用 .gitattributes
来比较 .odt 文件、libreofice 编写器文件和 difftool。
按照本指南:http://www-verimag.imag.fr/~moy/opendocument/ 我制作了一个 .gitattributes
文件 .git 属性:
*.ods diff=odf
*.odt diff=odf
*.odp diff=odf
*.ods difftool=odf
*.odt difftool=odf
*.odp difftool=odf
这使得 git 比较 .odt 中的文本,但是当 git difftool 启动 kdiff3 来比较 .odt 文件时,我得到这个弹出错误:
Some input characters could not be converted to valid unicode.
You might be using the wrong codec. (e.g. UTF-8 for non UTF-8 files).
Don't save the result if unsure. Continue at your own risk.
Affected input files are in A, B.
...文件中的所有字符都是胡言乱语。
出了什么问题?我该如何解决这个问题?
PS:
我不知道这是否重要,但我想我还没有配置 'diff.tool',因为每次我命令:
$ git difftool
我得到这个输出:
This message is displayed because 'diff.tool' is not configured.
See 'git difftool --tool-help' or 'git help config' for more details.
'git difftool' will now attempt to use one of the following tools:
opendiff kdiff3 tkdiff xxdiff meld kompare gvimdiff diffuse diffmerge ecmerge p4merge araxis bc codecompare emerge vimdiff
Viewing (1/1): 'diffexperiment.odt'
Launch 'kdiff3' [Y/n]:
难道这就是 kdiff3 似乎不能与 odt2txt 一起工作的原因吗?
编辑:我重新尝试使用 Microsoft Word 文档执行此操作并取得了更进一步的进展
我试过 .kdiff3rc 配置... none 我添加的选项似乎使不可读的字符可读。 我把对比工具改成了vimdiff;当我在 Microsoft Word 文档上执行 git difftool 时,vimdiff 显示了一个以 .xml 结尾的文件列表,而不是不可读的字符。
当我在显示的其中一个文件上按下回车键时:
<?xml version="1.0" encoding="UTF-8"?>
" Browsing zipfile /tmp/4LMJbj_HI I am writing something here..docx |<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Override PartName
" Select a file with cursor and press ENTER |="/_rels/.rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Overr
|ide PartName="/word/settings.xml" ContentType="application/vnd.openxmlformats-officedocument.w
_rels/.rels |ordprocessingml.settings+xml"/><Override PartName="/word/_rels/document.xml.rels" ContentType=
word/settings.xml |"application/vnd.openxmlformats-package.relationships+xml"/><Override PartName="/word/fontTabl
word/_rels/document.xml.rels |e.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+x
word/fontTable.xml |ml"/><Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officed
word/numbering.xml |ocument.wordprocessingml.styles+xml"/><Override PartName="/word/document.xml" ContentType="app
word/styles.xml |lication/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/><Override Part
word/document.xml |Name="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-p
docProps/app.xml |roperties+xml"/><Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlfo
docProps/core.xml |rmats-package.core-properties+xml"/>
[Content_Types].xml |</Types>
我在这个问题上发布了一个新问题 here。
除了 .gitattribute
之外,您还需要 配置 odf
的含义:
git config diff.odf.textconv odt2txt
并且您的 $PATH (Linux/Mac)
或 %PATH%
(Windows) 中需要 odt2txt
(从 OpenDocument 文本到纯文本的简单转换器)。
无需配置difftool
,因为默认kdiff3
就足够了。
但是 kdiff3
需要打开一个文本文件,因此需要 odt2txt
(为了首先将文档转换为文本文件)
有关 textconv
的更多信息,请参阅“Performing text diffs of binary files”:
Sometimes it is desirable to see the diff of a text-converted version of some binary files. For example, a word processor document can be converted to an ASCII text representation, and the diff of the text shown.
Even though this conversion loses some information, the resulting diff is useful for human viewing (but cannot be applied directly).The
textconv
config option is used to define a program for performing such a conversion. The program should take a single argument, the name of a file to convert, and produce the resulting text on stdout.Note
The text conversion is generally a one-way conversion; This means that diffs generated by
textconv
are not suitable for applying.For this reason, only
git diff
and thegit log
family of commands (i.e.,log
,whatchanged
,show
) will perform text conversion.
git format-patch
will never generate this output.If you want to send somebody a text-converted diff of a binary file (e.g., because it quickly conveys the changes you have made), you should generate it separately and send it as a comment in addition to the usual binary diff that you might send.
OP Jack mentions
On Linux I ran in my home directory:
$ git config diff.odf.textconv odt2txt
I had
odt2txt
installed... and I assumeodt2txt
is in$PATH
, because when I run$ odt2txt
, I get information onodt2txt
.
However, none of those things seem to makegit diff .odt
files for some reason.
When I$ git diff fileone.odt filetwo.odt
, I still get the output of Binary files fileone.odt and filetwo.odt differ instead of exactly how the text differentiates.
Not sure why it's not working.
我猜你的情况是 kdiff3
Some input characters could not be converted to valid unicode. You might be using the wrong codec. (e.g. UTF-8 for non UTF-8 files)....
抱怨是因为它找不到特定字体的特定字符的字形,即它无法绘制它(它们)。
kdiff3 有很多配置选项可以在 ~/.kdiff3rc 配置文件中设置(here 是例子)。我会玩其中一些与编码和字体相关的东西。例如,从更改字体开始,例如
Font=Arial
顺便说一句,当你用你的编辑器打开这些 odt 文件时 - 它是你可读的字体?
PS 也可以在命令行中将选项传递给 kdiff3:kdiff3 --cs "Option1=Val1" --cs "Option2=Val2" --cs ...