如何使用difftool差异.odt文件? kdiff3 diff输出不可读的字符 [英] How to diff .odt files with difftool? kdiff3 diff outputs unreadable characters

查看:101
本文介绍了如何使用difftool差异.odt文件? kdiff3 diff输出不可读的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在git中,我尝试使用.gitattributes将.odt文件,libreofice编写器文件与difftool进行比较. 遵循本指南: http://www-verimag.imag.fr/~moy/opendocument/我为此创建了一个.gitattributes文件.gitattributes:

In git I'm trying to use .gitattributes to compare .odt files, libreofice writer files, with difftool. From following this guide: http://www-verimag.imag.fr/~moy/opendocument/ I made a .gitattributes file .gitattributes with this:

*.ods diff=odf
*.odt diff=odf
*.odp diff=odf

*.ods difftool=odf
*.odt difftool=odf
*.odp difftool=odf

这使git diff比较.odt中的文本,但是当git difftool启动kdiff3比较.odt文件时,出现此弹出错误:

This made git diff compare the text in .odt, however when git difftool launches kdiff3 to compare the .odt files, I get this pop-up error:

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.

...并且文件中的所有字符都是巨型字符.

...and all of the characters in the files are mumbo jumbo.

出了什么问题?我该如何解决?

What went wrong? How do I fix this?

PS:

我不知道这是否重要,但我想我没有配置'diff.tool',因为每次我命令:

I don't know if this is important but I guess I haven't configured 'diff.tool', because every time I command:

$ 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一起使用的原因吗?

Could that be why kdiff3 doesn't seem to work with odt2txt?

我尝试对Microsoft Word文档执行此操作,并进一步了解了

I retried to do this with Microsoft Word documents and got a little further here.

我使用.kdiff3rc配置进行操作...我添加的所有选项似乎都无法读取不可读的字符. 我将比较工具更改为vimdiff.当我在Microsoft Word文档上执行git difftool时,vimdiff会显示一个以.xml结尾的文件列表,而不是不可读的字符.

I played around with .kdiff3rc configuration... none of the options I added seemed to make the unreadable characters readable. I changed the comparison tool to vimdiff; and when I did git difftool on microsoft word documents, vimdiff displayed a list of files ending in .xml instead of unreadable characters.

当我按Enter时,输入以下显示的文件之一:

When I pushed enter on one of the files this displayed:

<?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>

我对此问题发布了一个新问题

I posted a new question on this issue here.

推荐答案

除了.gitattribute之外,您还需要 configure odf的含义:

You would need, in addition of the .gitattribute, to configure what odf means:

git config diff.odf.textconv odt2txt

您需要 odt2txt (来自在$PATH (Linux/Mac)%PATH%(Windows)中将OpenDocument文本转换为纯文本.

And you need odt2txt (a simple converter from OpenDocument Text to plain text) in your $PATH (Linux/Mac) or %PATH% (Windows).

无需配置difftool,因为默认情况下kdiff3就足够了.
但是kdiff3需要打开一个文本文件,因此需要odt2txt(以便首先将文档转换为文本文件)

No need to configure difftool, as kdiff3 is enough by default.
But kdiff3 needs to open a text file, hence the need to odt2txt (in order to convert first the doc into a text file)

有关textconv的更多信息,请参见"对二进制文件进行文本比较 :

For more on textconv, see "Performing text diffs of binary files":

有时候,希望看到一些二进制文件的文本转换版本的差异.例如,可以将文字处理程序文档转换为ASCII文本表示形式,并显示文本的差异.
即使此转换会丢失一些信息,但产生的差异仍可用于人类查看(但无法直接应用).

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).

textconv config选项用于定义用于执行这种转换的程序.该程序应使用单个参数,即要转换的文件的名称,并在stdout上生成结果文本.

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.

文本转换通常是单向转换;这意味着textconv生成的差异不适合应用.

The text conversion is generally a one-way conversion; This means that diffs generated by textconv are not suitable for applying.

由于这个原因,只有git diffgit log系列命令(即logwhatchangedshow)将执行文本转换.
git format-patch将永远不会生成此输出.

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 提到


The OP Jack mentions in the comments:

在Linux上,我在主目录中运行:

On Linux I ran in my home directory:

$ git config diff.odf.textconv odt2txt

我已经安装了odt2txt ...并且我认为odt2txt$PATH中,因为当我运行$ odt2txt时,我会获得有关odt2txt的信息.
但是,由于某种原因,这些东西似乎都不制作git diff .odt文件.
当我$ git diff fileone.odt filetwo.odt时,仍然得到二进制文件fileone.odt和filetwo.odt的输出,而不是文本的确切区​​别.
不知道为什么它不起作用.

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.

这篇关于如何使用difftool差异.odt文件? kdiff3 diff输出不可读的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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