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

大兔子大兔子 提交于 2019-11-28 11:34:55

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).

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