LoginSignup
23
18

More than 5 years have passed since last update.

Git for Windows 2.xのシステムコンフィグファイルは2つある

Last updated at Posted at 2016-01-24

問題

Unix系OSならば、git config --listの出力は、

# 全ユーザで共有している設定を出力する
git config --system --list

# ユーザ固有の設定を出力する
git config --global --list

# リポジトリ固有の設定を出力する
git config --local --list

の3つのコマンドを続けて実行したときと同じものになるはずである。

ところが、Git for Windows 2.7.0のGit Bashで同じコマンドを実行してみると、

$ git config --list
core.symlinks=false
core.autocrlf=false
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
help.format=html
http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
diff.astextplain.textconv=astextplain
rebase.autosquash=true
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true
core.hidedotfiles=dotGitOnly
$ git config --system --list
fatal: unable to read config file 'C:\Program Files\Git\mingw64/etc/gitconfig': No such file or directory
$ git config --global --list

$ git config --local --list
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true
core.hidedotfiles=dotGitOnly

git config --listにあったcore.symlinksからrebase.autosquashまでの設定が--systemにも--globalにも--localにも見当たらない。
これらの設定はいったいどこで定義されているのだろうか?

答え

Git for Windows 2.xは全ユーザで共有している設定を保存する第二のファイルを持っており、そちらに定義されている。

$ git config --file /c/ProgramData/git/config --list
core.symlinks=false
core.autocrlf=false
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
help.format=html
http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
diff.astextplain.textconv=astextplain
rebase.autosquash=true

Git for Windows 2.xは次の順で設定ファイルを読み込む。(下のファイルに書かれた設定の方が優先順位が高い)

  1. C:\ProgramData\git\config(git config --file /c/ProgramData/git/configで読み書き可能)
  2. C:\Program Files\Git\mingw64\etc\gitconfig(git config --systemで読み書き可能)
  3. C:\Users\(ユーザ名)\.gitconfig(git config --globalで読み書き可能)
  4. (Gitリポジトリへのパス)\.git\config(git config --localで読み書き可能)

全ユーザで共有している設定を保存するファイルが2つある理由はよく分からなかった。

参考リンク

23
18
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
23
18