tags:

views:

677

answers:

2

I needed to use in my old Git similar settings to the following to be able use difftool. The settings are not exactly the same, since I by accident removed my old .gitconfig.

 [merge]
     tool=opendiff

 [mergetool]
     tool=opendiff

 [difftool]
     difftool=opendiff

I have an empty .gitconfig at Home. I can use still the opendiff -tool. This is a surprise, since it should be impossible.

How do Git's difftool settings work internally?

+3  A: 

You can see a complete setup using mergetool and difftool here.

If the setting seems to still be active, it may be because it has been set globally or in your account, since there are three files where git-config will search for configuration options:

$GIT_DIR/config

Repository specific configuration file. (The filename is of course relative to the repository root, not the working directory.)

~/.gitconfig

User-specific configuration file. Also called "global" configuration file at your Git's installation location:

$(prefix)/etc/gitconfig

System-wide configuration file.


Git saves the user info wherever you say it to save when you type 'git config':

From git config manual page:

The file-option can be one of --system, --global or --file which specify where the values will be read from or written to.
The default is to assume the config file of the current repository, .git/config unless defined otherwise with GIT_DIR and GIT_CONFIG.

You can override these rules either by command line options or by environment variables. The --global and the --system options will limit the file used to the global or system-wide file respectively.
The GIT_CONFIG environment variable has a similar effect, but you can specify any filename you want.

May be you had that environment variable set in your previous installation?

GIT_CONFIG

Take the configuration from the given file instead of .git/config. Using the "--global" option forces this to ~/.gitconfig. Using the "--system" option forces this to $(prefix)/etc/gitconfig.

Note: for Mac OsX, $(prefix) should be /usr/local (if you installed Git as described here)

make prefix=/usr/local all
sudo make prefix=/usr/local install
which git
VonC
@VonC: How can you change the setting where Git saves the user info? --- My old Git saved everything to .gitconfig. My current Git saves everything to $GIT_DIR/config.
Masi
@VonC: Where is the folder $(prefix)/etc/gitconfig? I did not find it in my OS/X.
Masi
@Masi, oh, that the default *Unix* directory, but I will check where that translate for a Mac
VonC
Got it: http://www.killswitchcollective.com/articles/36_git_it_got_it_good : /usr/local
VonC
@VonC: Is [---] a comment in Git such that I can use only % tool=opendiff % once in my .gitconfig?
Masi
The new question is at http://stackoverflow.com/questions/1081186/is-a-comment-in-git-in-gitconfig
Masi
+2  A: 

You have also (in addition to remembering about many places Git searches for configuration, as stated in response by VonC) to remember that both git-difftool and git-mergetool provide some autodetection / autodiscovery (in some fixed order of preference) of which tools you have available.

This might be why "git difftool" invokes opendiff on your computer.

Jakub Narębski
+1. I tried to check in the script 'git-merge-tool' where that default auto-detection setting might take place, but did not find anything at first glance. Do you know if the auto-detection is scripted, or is within some git executable?
VonC
@VonC: Great question!
Masi
VonC's question is now at http://stackoverflow.com/questions/1064103/is-gits-auto-detection-scripted-or-is-it-within-some-git-executable
Masi
@VonC: Check 'guess_merge_tool' function in 'git-mergetool--lib' (in "git --exec-dir").
Jakub Narębski