git config

本文中使用到的参数

-e 编辑配置文件
--global 全局配置 ~/.gitconfig
--system 系统配置 /etc/gitconfig
--unset 删除配置项

一、配置文件

$ cd /path/to/workspace/source/
$ git config -e
编辑 /path/to/workspace/source/.git/config


$ git config -e --global
编辑 ~/.gitconfig

$ git config -e --system
编辑 /etc/gitconfig

配置文件内容实例如下:
[core]
        repositoryformatversion = 0
        filemode = false
        logallrefupdates = true
[remote "origin"]
        url = "........."(不能外链,故删掉了)
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
[branch "3.2.0.RC2"]
        remote = origin
        merge = refs/heads/3.2.0.RC2


二、git配置INI文件

git配置文件采用的INI文件格式,git config命令可对INI文件进行操作

1)增加配置项:

$ git config user.name "Silenter Wat"
$ git config user.email "xxxxxx"
.git/config文件中增加结果如下
[user]
        name = Silenter Wat
        email = xxxxxx

$ git config x.y.z b
结果如下
[x "y"]
        z = b
其中选项的名字可以是任意的,不会报错,但是git命令可能不会使用的
如上面示例。

在~/.gitconfig及/etc/gitconfig增加分别如下:
$ git config --global user.name "Silenter Wat"
$ git config --global user.email "xxxxxx"

$ git config --system user.name "Silenter Wat"
$ git config --system user.email "xxxxxx"

2)删除配置选项
$ git config --unset u.t
$ git config --unset --global user.name
$ git config --unset --system user.email
会删除掉u.t配置项

3)查看某个选项的值
$ git config user.name
Silenter Wat

4)指定配置文件
增加修改
$ GIT_CONFIG=test.ini git config a.b.c.d "Hello world"
$ vim test.ini
[a "b.c"]
        d = Hello world

查看
$ GIT_CONFIG=test.ini git config a.b.c.d

删除
$ GIT_CONFIG=test.ini git config --unset a.b.c.d

三、常用配置
1)用户邮箱
$ git config --global user.name "Silenter Wat"
$ git config --global user.email "xxxxxx“

2)别名
$ git config --system alias.st status
$ git config --system alias.ci commit
$ git config --system alias.co checkout
$ git config --system alias.br branch

3)开启颜色显示
$ git config --global color.ui true


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值