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万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章