is it possible to use Mercurial version control to track Word or PDF files? Is there any limitation or problem?
4 Answers
Yes.
You will be able to do meaningful diffs for MS Word documents.
If you have TortoiseHg installed and you have set up a repository, right-click the file for which you want to check the diffs.
On the context menu, click TortoiseHg > Visual Diffs.
In the Visual Diffs dialog, select docdiff, instead of kdiff3.
Double-click the file in the Visual Diffs dialog.
MS Word will open a Compare Result Word document, which will show the differences between the current version of the document and the previous version as Tracked Changes.
-
Very cool! One question: I can only do a visual diff if I have changes that are not committed and it only compares my current changes with the last commit. Is there a way to specify which two revisions to compare? Commented Mar 5, 2012 at 19:45
-
You can right click on any revision and do a "Diff to Local" @JasonDown to compare with the current working directory.– EdwardCommented Jul 12, 2012 at 22:12
Yes, but of course you won't be able to diff in any meaningful way. The files will therefore be treated as binary during merges.
Mercurial is perfectly capable of tracking binary files:
Mercurial generally makes no assumptions about file contents. Thus, most things in Mercurial work fine with any type of file.
Mercurial stores a binary diff regardless of the file type. The problem with PDF/Word files is that a little change to them usually causes a huge difference in their binary representation on disk. .docx
Documents are stored as a zipped xml, due to the zipping a single flipped bit inside the archive can cause the zip archive to look completely different.
If you don't grow your repository too large, you probably won't experience any issues using Mercurial.
-
1except if the binary is such that small changes to the document make large binary changes then the binary diff will be about the same size as the file for each version. i'd use words xml format rather than the binary ones– jk.Commented Mar 17, 2010 at 11:43
-
1@jk: You're right, in fact I assumed he used the office 2007 format, only problem is it is zipped internally AFAIK. But people tend to blame the VCS for not handling binaries correct all too often. Commented Mar 17, 2010 at 11:49
-
2
-
1then you will get efficient storage in hg, and could conceivably use normal text merge to merge docs, there do appear to be special word merge tools available which may (or may not) be better though– jk.Commented Mar 17, 2010 at 14:18
Beware the suggested
cmd.pdfdiff = [\path\to\diffpdf.exe]
opts.pdfdiff= -a $local $other
$local and $other have no meaning in the extdiff context. The literal strings "$local" and "$other", not the file names, will be passed to "diffpdf.exe". I found this the hard way.
cmd.pdfdiff = [\path\to\diffpdf.exe]
opts.pdfdiff= -a
will work and the two files will be passed as parameters following the "-a". c.f. https://www.mercurial-scm.org/wiki/ExtdiffExtension where it is stated:
Each custom diff commands can have two parts: a 'cmd' and an 'opts' part. The cmd.xxx option defines the name of an executable program that will be run, and opts.xxx defines a set of command-line options which will be inserted to the command between the program name and the files/directories to diff
For Pdf files, I was able to get the GPL licensed DiffPDF hooked up to do comparisons between revisions of pdf files.
I added the following to my mercurial.ini
file:
[extdiff]
cmd.pdfdiff = [\path\to\diffpdf.exe]
opts.pdfdiff= -a $local $other
[diff-patterns]
**.pdf=pdfdiff
Now when I click on the pdf file in tortoisehg (or use hg pdfdiff
at the cmd line), it opens the two files for comparison. Since my pdf's tend to contain images, I use the appearance comparer (-a
in opts
). If you have mostly text, you can use -w
instead.
It defaults to highlighting to show the diffs. I prefer the Src Xor Dest option for displaying the differences, but I don't think there is a cmd line option for that.
-
3DiffPDF is NOT GPL licensed: "DiffPDF is a commercial Windows graphical user interface (GUI) application ..." Commented Jan 15, 2018 at 22:36