Git環境變量
-
linux系統
Git 有三種級別的環境變量,它們分別是: 系統 Git 配置(--system)、當前用戶 Git 配置(--global) 和 當前項目 Git 配置(無)。 每一個級別的配置都會覆蓋上層的相同配置,即:當前項目配置 > 當前用戶配置 > 系統配置
-
windows系統
在 Windows 系統上,Git 會找尋用戶主目錄下的 .gitconfig 文件 主目錄即 $HOME 變量指定的目錄,一般都是 C:\\Documents and Settings\\$USER $USER 是當前用戶的登錄名 此外, Git 還會嘗試找尋 Git 安裝目錄下的 gitconfig 文件
配置Git
-
配置用戶信息
可以使用以下命令配置個人的用戶名稱和電子郵件地址$ git config --global user.name "lik" $ git config --global user.email "[email protected]"
1、如果用了 -global選項,那麼更改的配置文件是位於你用戶目錄下的那個,以後我們所有的項目都會默認使用這裏配置的用戶信息
2、如果要配置某個特定的項目中使用其他名字或者郵箱,只要去掉 --global 選項即可 -
配置文本編輯器(瞭解即可)
我們可以設置 Git 默認使用的文本編輯器
一般情況下可能會配置成 vi 或 vim 當然我們也可以配置成其它的,比如 emacs$ git config --global core.editor emacs
-
配置差異分析工具(瞭解即可)
差異分析工具是用在解決合併衝突時查看文件差異的
我們可以將默認的差異分析工具改成 vimdiff$ git config --global merge.tool vimdiff
查看配置信息
-
要檢查已有的配置信息,可以使用 git config --list 命令
$ git config --list core.symlinks=false core.autocrlf=true core.fscache=true color.diff=auto color.status=auto color.branch=auto color.interactive=true help.format=html rebase.autosquash=true http.sslbackend=openssl http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt credential.helper=manager core.editor="C:\\Program Files (x86)\\Notepad++\\notepad++.exe" -multiInst -notabbar -nosession -noPlugin filter.lfs.clean=git-lfs clean -- %f filter.lfs.smudge=git-lfs smudge -- %f filter.lfs.process=git-lfs filter-process filter.lfs.required=true user.name=lik user.email=[email protected]
如果看到重複的變量名,那就說明它們來自不同的配置文件(比如 /etc/gitconfig 和 ~/.gitconfig),不過 Git 實際採用的是最後一個
也可以直接查閱某個環境變量的設定,只要把特定的名字跟在後面即可$ git config user.name lik
-
我們也可以直接查看配置文件
比如我們可以用 cat ~/.gitconfig 或 cat /etc/gitconfig 命令查看配置 (linux系統下)
直接找到對應的配置文件打開查看即可(windows系統下)