How to get winmerge to show diff for new file in git?
Asked Answered
G

2

6

I can get winmerge to show me diffs for modified file. But for new files, winmerge gives a dialog saying 'Left path is invalid!'. I want it to show the left pane as empty and right pane with the contents of the file.

$ git difftool head^ newfile.txt

winmerge Dialog:

enter image description here

I'm on git version 2.8.2.windows.1

This is my git config for difftool:

[diff]
    tool = winmerge
[difftool]
    prompt = false
[difftool "winmerge"]
    cmd = \"C:\\Program Files (x86)\\WinMerge\\WinMergeU.exe\" -e -ub -wl \"$LOCAL\" \"$REMOTE\"

What am I missing?

Gruff answered 28/9, 2016 at 20:14 Comment(1)
So far, I am seeing this similar question: https://mcmap.net/q/341396/-git-difftool-winmerge-with-new-filesSclera
G
8

I could not find this exact workaround so I'm posting this. Hopefully, someone finds it useful.

I use a winmerge.sh script which simply passes an already created empty file for newly added (or removed) file. The script is in a dir that's on my PATH or /git/cmd/ dir for git bash.

winmerge.sh (similar to one here)

#!/bin/sh
# $1 is $LOCAL
# $2 is $REMOTE
NULL="/dev/null"
empty="$HOME/winmerge.empty"
if [ "$2" = "$NULL" ] ; then
    # added
    "D:/setups/WinMerge/WinMergeU.exe" -e -ub -wl -wr "$1" "$empty"
elif [ "$1" = "$NULL" ] ; then
    # removed
    "D:/setups/WinMerge/WinMergeU.exe" -e -ub -wl "$empty" "$2"
else
    # modified
    "D:/setups/WinMerge/WinMergeU.exe" -e -ub -wl "$1" "$2"
fi

I keep an empty file winmerge.empty at this path $HOME (which is c:/users/<username>).

I use the sh script in .gitconfig.

.gitconfig

[diff]
    tool = winmerge
[difftool]
    prompt = false
[difftool "winmerge"]
    cmd = winmerge.sh "$LOCAL" "$REMOTE"

Note:

To diff untracked files (new files) also before committing, I do

$ git add -N --no-all .

then use difftool. -N --no-all only adds the path of new files to index but not their content (--no-all is required to NOT stage the deleted files).

Gruff answered 15/10, 2016 at 20:25 Comment(1)
Thank you, that helped me a lot with a similar issue!Argilliferous
H
1

This issue with WinMerge was addressed in release v2.16.34 via PR #2056. It changed WinMerge so that \\.\nul is recognized and treated like a blank file.

Hinrichs answered 9/4 at 2:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.