Jac*_*ack 5 git version-control diff git-diff git-difftool
我一直在关注本指南,了解如何区分 Microsoft Word 文档,但我遇到了这个错误:
Usage: /usr/bin/docx2txt.pl [infile.docx|-|-h] [outfile.txt|-]
/usr/bin/docx2txt.pl < infile.docx
/usr/bin/docx2txt.pl < infile.docx > outfile.txt
In second usage, output is dumped on STDOUT.
Use '-h' as the first argument to get this usage information.
Use '-' as the infile name to read the docx file from STDIN.
Use '-' as the outfile name to dump the text on STDOUT.
Output is saved in infile.txt if second argument is omitted.
Note: infile.docx can also be a directory name holding the unzipped content
of concerned .docx file.
fatal: unable to read files to diff
Run Code Online (Sandbox Code Playgroud)
解释我是如何出现该错误的:我在要与之进行比较的存储库中创建了一个 .gitattributes。.gitattributes 看起来像这样:
*.docx diff=word
*.docx difftool=word
Run Code Online (Sandbox Code Playgroud)
我已经安装了 docx2txt。我在 Linux 上。我创建了一个名为 docx2txt 的文件,其中包含以下内容:
#!/bin/bash
docx2txt.pl $1 -
Run Code Online (Sandbox Code Playgroud)
我$ chmod a+x
docx2txt 并将 docx2txt 放在 /usr/bin/
我做了:
$ git config diff.word.textconv docx2txt
Run Code Online (Sandbox Code Playgroud)
然后尝试比较两个 Microsoft Word 文档。那是我收到上面提到的错误的时候。
我错过了什么?如何解决此错误?
PS:我不知道我的 shell 是否可以找到 docx2txt 因为当我这样做时:
$ docx2txt
Run Code Online (Sandbox Code Playgroud)
我的终端冻结,处理一些东西,但不输出任何东西,当我执行这些命令时,会发生这种情况:
$ man docx2txt
No manual entry for docx2txt
$ docx2txt --help
Can't read docx file <--help>!
Run Code Online (Sandbox Code Playgroud)
更新进度:我将 docx2txt 更改为
#!/bin/bash
docx2txt.pl "$1" -
Run Code Online (Sandbox Code Playgroud)
正如 pmod 所建议的,现在git diff <commit>
可以从命令行工作!好极了!但是,当我尝试
$ git difftool <commit>
Run Code Online (Sandbox Code Playgroud)
git 启动 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).
Don't save the result if unsure. Continue at your own risk.
Affected input files are in A, B.
Run Code Online (Sandbox Code Playgroud)
...并且文件中的所有字符都是笨拙的。命令行正确显示差异文本,但由于某种原因,kdiff3 无法正确显示差异文本。
如何在 kdiff3 或其他 gui 工具中正确显示差异文本?我应该将 kdiff3 更改为其他工具吗?
额外:由于这些命令,我的 shell 似乎无法找到 docx2txt:
$ which doctxt
which: no doctxt in (/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl)
$ which docx2txt
/usr/bin/docx2txt
Run Code Online (Sandbox Code Playgroud)
根据使用情况,doc2txt.pl需要正好两个参数或零个参数。在第一种(您的)情况下,参数要么是文件名,要么是“-”。因此,当作为第一个参数传递的文件名中至少有一个空格时,您的包装器脚本看起来是正确的。在这种情况下,扩展$1文件名部分后将作为单独的参数传递,因此工具会输出使用信息,因为它读取超过 2 个参数。
尝试使用引号以避免文件名分割:
#!/bin/bash
docx2txt.pl "$1" -
Run Code Online (Sandbox Code Playgroud)
PS:我不知道我的shell是否能找到docx2txt
你可以检查一下
$ which docx2txt
Run Code Online (Sandbox Code Playgroud)
如果您看到路径,则可以找到工具(二进制或可运行脚本)(基于 PATH 环境变量)。
因为当我这样做时:
$ docx2txt
我的终端冻结,正在处理某些内容,但不输出任何内容
如果没有参数,您的脚本将执行doc2txt.pl -根据工具的使用情况,它需要通过 STDIN 传递的输入文件,即您正在输入的内容。因此,它看起来像是悬挂和处理某些东西,但实际上只捕获您的输入。