How to automatically use git diff --word-diff option for *.tex files but not others?

做~自己de王妃 提交于 2019-12-04 11:21:53

See the Generating diff text section of the gitattributes documentation. However, to automatically get word diffs just for *.tex files, you must put this together with additional information there and in some other documents.

Also, at least in my current git version (2.7.4), the built-in regex for tex files is broken:

fatal: Invalid regular expression: \\[a-zA-Z@]+|\\.|[a-zA-Z0-9<80>-<FF>]+|[^[:sp

so I have to work around that even harder.

Putting these all together:

$ cat .gitattributes
*.tex   diff=tex
$ git config --get diff.tex.wordregex
\\[a-zA-Z]+|[{}]|\\.|[^\{}[:space:]]+

(this regex is straight from the gitattributes documentation), plus one more configuration item and one driver:

$ git config --get diff.tex.command
git-word-diff-driver
$ cat ~/scripts/git-word-diff-driver
#! /bin/sh
#
# args are:
# path old-file old-hex old-mode new-file new-hex new-mode
git diff --word-diff $2 $5
exit 0

(This script might be improved, but it shows the general idea. The exit 0 is required since git diff has a nonzero exit if the files differ, as they tend to. Fortunately there is no need to protect against endless recursion since git diff --word-diff path1 path2 does not re-invoke the gitattributes driver.)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!