我们用于处理Word文档(.doc)的方法同样适用于处理OpenOffice.org创建的OpenDocument文本文档(.odt)。
把下面这行添加到.gitattributes文件:
*.odt diff=odt
然后在.git/config 文件中设置odt过滤器:
[diff "odt"]
binary = true
textconv = /usr/local/bin/odt-to-txt
OpenDocument文档实际上是多个文件(包括一个XML文件和表格、图片等文件)的压缩包。我们需要写一个脚本来提取其中纯文本格式的内容。创建一个文件/usr/local/bin/odt-to-txt(你也可以放到其他目录下),写入下面内容:
[code]#! /usr/bin/env perl
Simplistic OpenDocument Text (.odt) to plain text converter.
Author: Philipp Kempgen
if (! defined($ARGV[0])) {
print STDERR “No filename given!\n”;
print STDERR “Usage: $0 filename\n”;
exit 1;
}
my $content = ‘’;
open my $fh, ‘-|’, ‘unzip’, ‘-qq’, ‘-p’, ARGV[0], 'content.xml' or die !;
{
local $/ = undef; # slurp mode
$content = <$fh>;
}
close fh;
_ = content;
s/<text:span\b[^>]*>//g; # remove spans
s/<text:h\b[^>]*>/\n\n***** /g; # headers
s/<text:list-item\b[^>]*>\s*<text:p\b[^>]*>/\n -- /g; # list items
s/<text:list\b[^>]*>/\n\n/g; # lists
s/<text:p\b[^>]*>/\n /g; # paragraphs
s/<[^>]+>//g; # remove all XML tags
s/\n{2,}/\n\n/g; # remove multiple blank lines
s/\A\n+//; # remove leading blank lines
print "\n", _, “\n\n”;[/code]
然后把它设为可执行文件
chmod +x /usr/local/bin/odt-to-txt
现在git diff命令就可以显示.odt文件的变更了。
REF:http://cwiki.ossez.com/pages/viewpage.action?pageId=7045550