利用git+pandoc完成对word文档的版本控制

Pandoc简介

Pandoc是个好用的文本格式转化器。

1.安装

安装参考官网就好,支持Windows,macOS,Linux。Linux蛮多发行版自带这个,比如Ubuntu,或则说如果安装过Anacoda,那么pandoc也会同时装入电脑中。

我的电脑里装了Anacoda,所以直接拿来用就好了。

  1. pandoc基本使用

pandoc [OPTIONS] [FILES]

基本参数说明

其中 为输入的内容,其输入即可以来自文件,也可以来自标准输入甚至网页链接。而 为参数选项。主要的参数选项有:

-f 、-r # 指定输入文件格式,默认为 Markdown;

-t 、-w # 指定输出文件格式,默认为 HTML;

注意:上述两项pandoc可以根据文件拓展名自己识别,不输入也行

-o # 指定输出文件,该项缺省时,将输出到标准输出;

--highlight-style

列出支持的输出格式;

--list-extensions # 列出支持的 Markdown 扩展方案;

--list-highlight-languages # 列出支持代码高亮的编程语言;

--list-highlight-styles # 列出支持的代码高亮主题;

-v、--version # 显示程序的版本号;

-h、--help # 显示程序的帮助信息。

使用示范

pandoc input.docx -o output.md #把我的word转成markdown

pandoc input.md -o output.docx

实现对word文档的版本控制

参考教程地址:https://github.com/vigente/gerardus/wiki/Integrate-git-diffs-with-word-docx-files

This section was inspired by Martin Fenner's "Using Microsoft Word with git".

To configure git diff:

Install pandoc.

Tell git how to handle diffs of .docx files.

Create or edit file ~/.gitconfig (linux, Mac) or "c:\Documents and Settings\user.gitconfig" (Windows) to add

复制代码
 [diff "pandoc"]
   textconv=pandoc --to=markdown
   prompt = false
 [alias]
    wdiff = diff --word-diff=color --unified=1

In your paper directory, create or edit file .gitattributes (linux, Windows and Mac) to add

*.docx diff=pandoc

You can commit .gitattributes so that it stays with your paper for use in other computers, but you'll need to edit ~/.gitconfig in every new computer you want to use.

========================================================================================================================================

【.gitattributes】

稍微说明一下.gitatrributes这个文件。官网链接:gitattributes documents

这个文件是一个简单的文本文件,作用是为attributes提供一个路径名

文件的基本格式

pattern attr1 attr2 ...

是一个pattern跟随一串的attrs, 这个pattern我理解的是某种匹配模式,然后会找到符合这种匹配模式的文件,用后面的attrs对这个文件的操作进行规范。

上文中的 *.docx diff=pandoc 表示对于所有.docx的文件,在使用diff时,默认是使用[diff "pandoc"] 这个subsection里面的配置。

========================================================================================================================================

Now you can see a pretty coloured diff with the changes you have made to your .docx file since the last commit
git wdiff file.docx

To see all changes over time
git log -p --word-diff=color file.docx

利用git+pandoc完成对word文档的版本控制

相关推荐
Klaus_Wei7 小时前
git 高级命令模式典型应用--“同步云端 + 清理垃圾分支”的一键命令
git·git高级用法·git同步云端·git清理垃圾分支
妙娲种子8 小时前
配置git/创建第一个智能相册保存快照
git
what_20188 小时前
git一个账号在两台电脑登录 出现不同用户名
git
困鲲鲲8 小时前
ROS2系列 (13) : 常用Git指令入门(本地Git)
git·ros2
☆cwlulu13 小时前
git分支管理详解
开发语言·git·青少年编程
脑子不好的小菜鸟15 小时前
用vscode连接远端ubuntu无法git push,vscode无法连接centos
git·vscode·ubuntu·centos
__Witheart__17 小时前
Git 如何修改已有的分支名称
git
CodeCraft Studio19 小时前
国产化Excel处理控件Spire.XLS教程:如何使用 Java 将 TXT 文本转换为 Excel 表格
java·word·excel·spire·文档格式转换·txt转excel
秦jh_19 小时前
【git】分支管理
git
百锦再1 天前
第5章 所有权系统
运维·git·python·eclipse·go·github·负载均衡