git config

git config基本篇

使用Git的第一件事就是设置你的名字和email,这些就是你在提交commit时的签名。

示例1
$ git config --global user.name "Robin Hu"
$ git config --global user.email "hudashi@gmail.com"
执行了上面的命令后,会在你的主目录(home directory)建立一个叫~/.gitconfig 的文件. 内容一般像下面这样:
[user]
name = Robin Hu
email = hudashi@gmail.com

git默认的编辑器是GNU nano这样的编辑器,我可以通过如下的命令把它设置为vim编辑器

示例2
git config --global core.editor vim
我们可以通过git config -h来获得git config命令的一些基本语法:
 git config -h
usage: git config [options]


Config file location
    --global              use global config file
    --system              use system config file
    --local               use repository config file
    -f, --file <file>     use given config file


Action
    --get                 get value: name [value-regex]
    --get-all             get all values: key [value-regex]
    --get-regexp          get values for regexp: name-regex [value-regex]
    --replace-all         replace all matching variables: name value [value_regex]
    --add                 adds a new variable: name value
    --unset               removes a variable: name [value-regex]
    --unset-all           removes all matches: name [value-regex]
    --rename-section      rename section: old-name new-name
    --remove-section      remove a section: name
    -l, --list            list all
    -e, --edit            opens an editor
    --get-color <slot>    find the color configured: [default]
    --get-colorbool <slot>
                          find the color setting: [stdout-is-tty]


Type
    --bool                value is "true" or "false"
    --int                 value is decimal number
    --bool-or-int         value is --bool or --int
    --path                value is a path (file or directory name)


Other
    -z, --null            terminate values with NUL byte
   
Git 使用一系列的配置文件来存储你定义的偏好,它首先会查找/etc/gitconfig文件,该文件含有 对系统上所有用户及他们所拥有的仓库都生效的配置值, 如果传递--system选项给git config命令, Git 会读写这个文件。
接下来 Git 会查找每个用户的~/.gitconfig文件,你能传递--global选项让 Git读写该文件。
最后 Git 会查找由用户定义的各个库中 Git 目录下的配置文件(.git/config),该文件中的值只对该git库有效。 如果传递 --local 选项给git config命令, Git 会读写这个文件。 --local  选项是默认选项
 以上阐述的三层配置从一般到特殊层层推进,如果定义的值有冲突,以后面层中定义的为准,例如:在.git/config和/etc/gitconfig的较量中, .git/config取得了胜利。虽然你也可以直接手动编辑这些配置文件,但是运行git config命令将会来得简单些。
-l, --list 用于列出我们已经设置了的git的配置信息。
示例3
 git config --global -l
user.name=Robin Hu

user.email=hudashi@gmail.com


git高级配置:http://hubingforever.blog.163.com/blog/static/1710405792012312104651929/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值