Git配置文件

Git的配置文件全都是簡單的 .ini文件風格的文本文件。它們記錄了很多 Git 命令使用的各種選項和設置。
Git支持不同層次的配置文件。按照優先級遞減的順序,它們如下所示。
.git/config
版本庫特定的配置設置,可以用–file選項修改,是默認選項。這些設置擁有最高優先權。
~/.gitconfig
用戶特定的配置設置,可用–global選項修改。
/etc/gitconfig
這是系統範圍的配置設置,如果你有UNIX文件寫權限,你就可以用–system選項修改它。這些設置的優先級最低。

例如,要建立一個作者名和 email 地址,用於你對所有版本庫的所有提交,可以用 git congfig –global 命令給在$HOME/.gitconfig 文件裏的 user.name 和 user.email 賦值.

$ git config --global user.name "Jon Loeliger"
$ git config --global user.email "[email protected]"

或者,爲了設置一個版本庫特定的名字和 email 地址,覆蓋 –global 的設置,只需要省略 –global 標誌。

$ git config user.name "Jon Loeliger"
$ git config user.email "[email protected]"

使用 git config -l 列出在整組配置文件裏共同查找的所有變量的設置值。

$ mkdir new
$ cd new
$ git init

$ git config --global user.name "Jon Loeliger"
$ git config --global user.email "[email protected]"
$ git config user.email "[email protected]"

$ git config -l
core.symlinks=false
core.autocrlf=true
core.fscache=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
help.format=html
http.sslcainfo=D:/software/Git/mingw64/ssl/certs/ca-bundle.crt
diff.astextplain.textconv=astextplain
rebase.autosquash=true
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.required=true
credential.helper=manager
color.ui=auto
gui.recentrepo=C:/Users/Ang/Desktop/computer/Git
gui.recentrepo=C:/Users/Ang/Desktop/Android/Android_Project/PetApplication
gui.recentrepo=D:/Git/petApplication
user.name=Jon Loeliger
[email protected]
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true
[email protected]

因爲配置文件只是簡單的文本文件,所以可以通過 cat 命令來查看其內容,也可以通過你最喜歡的文本編輯器來打開它。

$ cat .git/config
[core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
[user]
    email = [email protected]

可以使用 –unset 選項來移除設置。

$ git config --unset --global user.email

配置別名:
如果經常輸入一條常用而複雜的 Git 命令,可以考慮爲它設置一個簡單的 Git 別名。

$ git config --global alias.show-graph \ 
    'log -- graph --abbrev-commit --pretty=oneline'

現在,當我使用 git show–graph 命令是, 就如同我已經輸入了帶所有選項的長長的git log 命令一樣。

發佈了40 篇原創文章 · 獲贊 2 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章