天天看點

git的三種環境變量

git有三種環境變量,分别以檔案的形式存放在三個不同的地方。可以在指令行中使用git config工具檢視這些變量。

1.系統變量。

存放在git的安裝目錄下:%Git%\etc\gitconfig。

若使用

git config

時用

--system

選項,讀寫的就是這個檔案:

$ git config --system core.symlinks

系統變量對所有使用者都适用。

2.使用者變量。

存放在使用者目錄下。例如windows xp存放在:

C:\Documents and Settings\$USER

\.gitconfig。

若使用

git config

時用

--global

選項,讀寫的就是這個檔案:

$ git config --global user.name

使用者變量隻适用于該使用者。

3.本地項目變量。

目前項目的 git 目錄中的配置檔案(也就是工作目錄中的

.git/config

檔案)。

若使用

git config

時用

--local

選項,讀寫的就是這個檔案:

$ git config --local remote.origin.url

本地變量隻對目前項目有效。

注:每一個級别的配置都會覆寫上層的相同配置,例如

.git/config

裡的配置會覆寫%Git%

/etc/gitconfig

中的同名變量。

其他config指令

$ git config --list 檢視所有環境變量

$ git config --system --list 檢視系統環境變量

$ git config --global --list 檢視使用者環境變量

$ git config --local --list 檢視本地環境變量

$ git config --[system/global/local] [varname] [yourname] 編輯環境變量

繼續閱讀