我有两个问题:
有没有办法在.docx
上查看Github
文件?我们已将所有作业上传到Github,但我们无法在浏览器中查看它。如果我们可以在不下载文件的情况下在浏览器中查看这些.docx
文件,那就太好了。
如何在git diff
文件格式上使用.docx
?我尝试使用catdoc
,但它对我不起作用。我认为之前在git diff
格式的Windows上使用了.doc
,但它在Mac上并不适用于我。
非常感谢。
答案 0 :(得分:6)
在.gitattributes中使用:
*.docx diff=zip
在.git / config中使用:
[diff "zip"]
textconv = unzip -c -a
作为奖励我的旧单词/ excel和新单词/ excel的设置:
在.gitattributes中使用:
*.doc diff=word
*.xsl diff=excel
*.xlsx diff=zip
*.docx diff=zip
在.git / config中使用:
[diff "word"]
textconv = strings
[diff "excel"]
textconv = strings
[diff "zip"]
textconv = unzip -c -a
答案 1 :(得分:3)
回答你的第二个问题 -
通常在您尝试
时Amcharts
您将获得表单的输出 -
二进制文件a / filename.docx和b / filename.docx不同
不是很有帮助。一个完美的方法是使用Pandoc。
创建或编辑文件〜/ .gitconfig(linux,Mac)或" c:\ Documents and Settings \ user.gitconfig" (Windows)添加(或使用git diff filename.docx
)
git config --global --edit
在带有.docx文件的git控制目录中,创建或编辑文件.gitattributes(linux,Windows和Mac)以添加
[diff "pandoc"]
textconv=pandoc --to=markdown
prompt = false
[alias]
wdiff = diff --word-diff=color --unified=1`
您可以提交 .gitattributes 以便在其他计算机上保留,但是您需要在每台要使用的新计算机中编辑〜/ .gitconfig。
现在,您可以看到自上次提交以来对.docx文件所做的更改的漂亮颜色差异
*.docx diff=pandoc
可以找到更多详细信息here。
答案 2 :(得分:3)
在Linux Mint 19.3上,可接受的解决方案(使用字符串/解压缩)对我来说效果不佳。对于大多数doc / docx / rtf / xls文件以及与LibreOffice对应的文件,以下内容似乎工作得很好。其中一些可能会通过cygwin / git bash在Windows上运行,但我尚未测试过;如果我提到的软件包在cygwin / git bash中不可用,那么我会寻找执行相同转换并用它们替换的python / perl脚本。
sudo apt install git pandoc catdoc odt2txt
。 mkdir ~/.config/git/ && touch ~/.config/git/attributes
(在Windows上应为mkdir "%USERPROFILE%\.config\git" && echo "" > "%USERPROFILE%\.config\git\attributes"
)${projectDir}/.git/info/attributes
): # handle windows *.reg files (utf-16 which git doesn't normally like)
*.reg diff=utf16
# handle misc common document formats
*.pdf diff=pdf
*.rtf diff=catdoc
# handle libre/open document formats
*.ods diff=ods2txt
*.odp diff=odp2txt
*.odt diff=odt2txt
# handle older common ms document formats
# note: ppt did not work for me
*.doc diff=catdoc
*.ppt diff=catppt
*.xls diff=xls2csv
# handle newer zipped ms document formats
# note: pptx and xlsx did not work for me
*.docx diff=pandoc
*.pptx diff=pandoc
*.xlsx diff=pandoc
~/.gitconfig
中或在项目范围的${projectDir}/.git/config
中)。其中大部分基于this article,但根据我自己的测试进行了更改。[core]
autocrlf = false
[diff]
guitool = kdiff3
[diff "odp2txt"]
textconv = odp2txt
binary = true
[diff "odt2txt"]
textconv = odt2txt
binary = true
[diff "ods2txt"]
textconv = ods2txt
binary = true
[diff "catdoc"]
textconv = catdoc
binary = true
# note catppt did not work for me
[diff "catppt"]
textconv = catppt
binary = true
[diff "xls2csv"]
textconv = xls2csv
binary = true
[diff "xlsx2csv"]
textconv = xlsx2csv
binary = true
[diff "pandoc"]
textconv=pandoc --to=markdown
prompt = false
[diff "pdf2txt"]
textconv=pdf2txt
binary = true
[diff "utf16"]
textconv = iconv -c -f UTF-16LE -t ASCII
即使从their github page下载了最新版本的pandoc,我也无法成功获得适用于xlsx,ppt或pptx的差异。即使使用Mint / Ubuntu / Debian存储库中的超级旧版本(2016年的v1.19.2.4),docx转换也可以正常工作。对于我使用的xlsx / pptx样本,我总是遇到“无效的UTF-8流致命”(旧版本)或“ UTF-8解码错误”(新版本)的情况。
这可能是由于我正在使用的示例文件(一些来自网络的示例以及一些通过转换LibreOffice文档创建的示例),我的系统设置,我正在使用的版本或其他原因造成的。
为了完整起见,在安装较新的pandoc之后,我使用的是:
$ uname -vipor
5.3.0-40-generic #32~18.04.1-Ubuntu SMP Mon Feb 3 14:05:59 UTC 2020 x86_64 x86_64 GNU/Linux
$ dpkg -l catdoc odt2txt pandoc git xlsx2csv|grep '^ii'
ii catdoc 1:0.95-4.1 amd64 text extractor for MS-Office files
ii git 1:2.17.1-1ubuntu0.5 amd64 fast, scalable, distributed revision control system
ii odt2txt 0.5-1build2 amd64 simple converter from OpenDocument Text to plain text
ii pandoc 2.9.2-1 amd64 general markup converter
ii xlsx2csv 0.20+20161027+git5785081-1 all convert xslx files to csv format
编辑:还尝试使用软件包xlsx2csv
进行xlsx转换,而不是使用pandoc,我也遇到了问题。可能与我的样本有关,但由于我实际上并没有做任何特别的事情来创建它们,因此我认为如果有的话,xlsx2csv / pandoc的覆盖范围/限制。
答案 3 :(得分:1)
有没有办法在Github上查看.docx文件?
尚未(2016年第4季度),除非Word文档是纯文本。
如何在.docx文件格式上使用git diff?
自Windows 1.9.5的git和Git for Windows 2.5.3(2015年9月,以及issue 355)以来,您不必进行任何自定义设置:
git diff -- myWord.docx
那会有效。 (它也适用于.doc
和.pdf
)
从Git for Windows 2.10.1开始,你也可以分享docm和dotm(见PR 128)。
答案 4 :(得分:0)
这是有问题的,据我所知,在github或任何其他git主机上都不可能。虽然git可用于版本化任何东西,但像git diff这样的东西会以纯文本形式返回两个版本的差异。无法辨认。
我觉得这不是没有理由的。世界上有无限的文件格式,其中许多是专有的。因此,代替支持像VLC这样的每种格式,git使用文本文件来处理所有事情。
即使git以某种方式支持docx,它也无法在终端内显示格式更改,更不用说cmd了。如果它只是文本,最好将其存储为文本文件。或者手动签出以前的版本以比较更改。
答案 5 :(得分:0)
.docx文件实际上是一个zip(你可以改变文件类型并在里面戳)。如果将.docx视为目录,则在主文件中将IS存储为XML样式文件,并且文本不是二进制文件。
可悲的是,没有carraige回归。否则在' document.xml'上执行文本dif目录中的文件真的很有用。作为XML文件行,文件中的条纹不会影响内容,因此可以添加它们。
答案 6 :(得分:0)
经过三心二意地绕过Stackoverflow和Google多年之后,我今天才发现官方git书中有walkthrough。
安装docx2txt
。在Ubuntu 16.04上,我只使用了官方存储库:
sudo apt-get install docx2txt
编写包装脚本(docx2txt
需要一些参数。),如下所示:
#! /usr/bin/env bash
docx2txt "$1" -
我调用了脚本d2t
,所以我将其添加到了$PATH
中的某个文件夹中。记住要使其可执行,以便git可以运行它。
chmod +x d2t
mv d2t /somewhere/in/your/PATH
现在通过将此块添加到.git/config
,使您的存储库意识到这一点:
[diff "word"]
textconv = d2t
*注意:book建议使用一条命令,我假设您也可以将--global
标志用于将过滤器应用于所有存储库:
git config --global diff.word.textconv d2t
对于您要在其中工作的存储库,编辑.gitattributes
:
*.docx diff=word
现在,您应该可以git diff
docx文档了。
diff --git a/goodpoint.docx b/goodpoint.docx
index 0d6e78c..4476023 100644
--- a/goodpoint.docx
+++ b/goodpoint.docx
@@ -1,7 +1,7 @@
Making many good points
1. Overview
-- 2l3k23lk
+- this is a test
- 23lkjl2k3j
2. Remarks
编辑:在git 2.7.4上尝试过。您不能checkout
和add
进行补丁补丁,而无需做更多工作。