banner
RegChien

RegChien

頭盔隔絕路人語,兩耳盡是自由聲。
telegram
twitter
bilibili
github
nintendo switch

Microsoft Word Local Version Control? Try Git + Pandoc

Word, as the most pervasive software among the three Office suites, has a lack of automatic file saving and version control. These features can only be accessed with OneDrive, whose software quality is unsatisfactory. For those who have NAS, it is not very cost-effective. Are there any third-party solutions that can help Microsoft solve this problem?

Introduction#

What is Version Control?#

Version control is a system that tracks and manages changes to files. It helps you keep track of changes to files, revert to previous versions, and collaborate on files with others.

There are two main types of version control systems: centralized and distributed. Centralized version control systems store all files on a central server. Distributed version control systems store files on all participants' workstations.

Git#

Git is a distributed version control system and is currently one of the most popular version control systems. It is easy to use and can be used for various projects.

Here are some of the benefits of using version control:

  • Track file changes: Version control helps you track changes to files, which is useful for reverting to previous versions or viewing the change history.
  • Revert to previous versions: If you accidentally delete or change a file, you can use version control to revert to a previous version.
  • Collaborate with others: Version control helps you collaborate on files with others. Everyone can work on their copy of the file and then merge the changes into the main branch.

Pandoc#

Pandoc is a free software that converts text to various formats, including HTML, PDF, LaTeX, EPUB, Docx, and more. It is developed by John MacFarlane and runs on Windows, Mac, and Linux. Pandoc is a widely used tool in academia and technology and can be used for writing and formatting documents, generating presentations, creating e-books, and more.

Powered by Google Bard

Implementation Logic#

Git was initially designed for version control of source code, and it supports plain text content very well. However, binary formats like Docx cannot generate text-level modification records in Git. Although it can still be used, version control cannot be previewed, which is no different from directly naming them as v2 and v3.

Therefore, we use Pandoc to convert Docx to Markdown and use git diff to let Markdown replace Docx to present the text-level preview version difference comparison.

Operation Steps#

  1. Install Git and Pandoc
  2. Configure Git
  3. Edit Word
  4. Git Commit

Install Git and Pandoc#

  1. Go to the Git official website, download and install the Git version corresponding to your operating system.
  2. Go to the Pandoc official website, download and install the Pandoc version corresponding to your system.

For macOS, it is recommended to use Homebrew to install Git and Pandoc: brew install git pandoc

Configure Git#

  1. In the User directory, open the .gitconfig file and add the following content at the end:

[diff "pandoc"]

textconv=pandoc --to=markdown

prompt = false
[alias]

wdiff = diff --word-diff=color --unified=1

CleanShot 2023-07-14 at 09.12.02@2x

  1. In the Word folder where we want to perform version control, initialize Git: git init

CleanShot 2023-07-14 at 09.11.15@2x

  1. Add .gitattributes and add the following content:

*.docx diff=pandoc

CleanShot 2023-07-14 at 09.13.43@2x

Edit Word#

CleanShot 2023-07-14 at 09.32.09@2x

Here, a demonstration document will have its English abstract deleted, and then the file will be saved.

Git Commit#

  1. By using git diff {file name}.docx, we can process the Docx format into Markdown

CleanShot 2023-07-16 at 00.03.57@2x

  1. In Git GUI Apps like Github Desktop, you can clearly see the changes made to this Docx file

CleanShot 2023-07-14 at 09.33.35@2x

Then you can use commands like Git commit to perform version control. You can learn more about advanced Git operations on the Git official website.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.