When calling git difftool
in a repository, git compares the modified files in the local repository with their match in the remote. To do so, it creates a temporary file for the remote, sets the variables LOCAL
and REMOTE
and calls whichever tool is specified for diffs in git's config.
By default, the temporary file is created in /tmp/<hash>_filename
. Is it possible to change this default location?
Long story short, I'm using git via windows subsystem for linux and I want to use a windows tool to do diff and merge. The problem is, /tmp
is not accessible from the Windows side, so I'd need to move the default location where git creates temporary files to somewhere accessible by Windows.
So far, all I could find was a suggestion to sudo mount -B /tmp /mnt/c/tmp
but this doesn't seem to work (/tmp
still points to the same directory as before...)
You can try setting the TMPDIR
environment variable.
From the POSIX manual:
TMPDIR
This variable shall represent a pathname of a directory made available for programs that need a place to create temporary files.
After a quick look at the git code (git/builtin/difftool.c
), I don't think configuring the temp directory is currently supported:
/* Setup temp directories */
tmp = getenv("TMPDIR");
xsnprintf(tmpdir, sizeof(tmpdir), "%s/git-difftool.XXXXXX", tmp ? tmp : "/tmp");
Seems like git is taking the TMPDIR
value, or "/tmp"
, if TMPDIR
is not defined.