Reputation: 1395
I would like to see git diff of Word .docx files in SourceTree on Windows.
Per default they shows up like this:
I have tried changing .gitattributes and .git\config but it does not work for the history in SourceTree. This sadly seems like a limitation in SourceTree 1, 2
Are there any ways to get a diff for Word .docx files in SourceTree on Windows?
Upvotes: 1
Views: 1680
Reputation: 1395
This solution will merge for comparison using the Word - Compare and merge two versions of a document. Using it like this:
You can also use Ctrl + D as a shortcut for External Diff
Drawbacks
This solution is based on ForNeVeR/ExtDiff.
First you create 2 files:
CompareWord.cmd
@echo off
powershell.exe -File "%~dpn0.ps1" %*
CompareWord.ps1
param(
[string] $BaseFileName,
[string] $ChangedFileName
)
$ErrorActionPreference = 'Stop'
function resolve($relativePath) {
(Resolve-Path $relativePath).Path
}
$BaseFileName = resolve $BaseFileName
$ChangedFileName = resolve $ChangedFileName
# Remove the readonly attribute because Word is unable to compare readonly
# files:
$baseFile = Get-ChildItem $BaseFileName
if ($baseFile.IsReadOnly) {
$baseFile.IsReadOnly = $false
}
# Constants
$wdDoNotSaveChanges = 0
$wdCompareTargetNew = 2
try {
$word = New-Object -ComObject Word.Application
$word.Visible = $true
$document = $word.Documents.Open($BaseFileName, $false, $false)
$document.Compare($ChangedFileName, [ref]"Comparison", [ref]$wdCompareTargetNew, [ref]$true, [ref]$true)
$word.ActiveDocument.Saved = 1
# Now close the document so only compare results window persists:
$document.Close([ref]$wdDoNotSaveChanges)
} catch {
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.MessageBox]::Show($_.Exception)
}
<your\path\to\>CompareWord.cmd
\"$LOCAL\" \"$REMOTE\"
Upvotes: 1