GIT配置

文章链接:http://www.liuschen.com

一直以来,用git和SVN都是懂得基本操作就行了,会克隆推送提交什么的,一直缺少一个全局性的把握,所以一旦设置出现问题就手足无措,即使知道了解决方法,不常用的知识往往也易于忘记。

git的配置分为,局部,全局和系统,作用域不同

git config [<file-option>] [type] [-z|--null] name [value [value_regex]]
git config [<file-option>] [type] --add name value
git config [<file-option>] [type] --replace-all name value [value_regex]
git config [<file-option>] [type] [-z|--null] --get name [value_regex]
git config [<file-option>] [type] [-z|--null] --get-all name [value_regex]
git config [<file-option>] [type] [-z|--null] --get-regexp name_regex [value_regex]
git config [<file-option>] [type] [-z|--null] --get-urlmatch name URL
git config [<file-option>] --unset name [value_regex]
git config [<file-option>] --unset-all name [value_regex]
git config [<file-option>] --rename-section old_name new_name
git config [<file-option>] --remove-section name
git config [<file-option>] [-z|--null] -l | --list
git config [<file-option>] --get-color name [default]
git config [<file-option>] --get-colorbool name [stdout-is-tty]
git config [<file-option>] -e | --edit

其中就是作用域

 --global              use global config file(全局)
--system              use system config file(系统)
--local               use repository config file(局部)
-f, --file <file>     use given config file(自定义)
--blob <blob-id>      read config from given blob object(自定义)

例子

1.查看仓库配置

git config -l[-list]
git config –-local -l
git config –-global -l
git config –-system -l

2.添加配置(键和值不可缺少)

git config –-local --add name value
git config –-global --add name value
git config –-system --add name value

3.修改配置

git config –-local  name value
git config –-global  name value
git config –-system  name value

4.删除配置

git config –-local  --unset name
git config –-global  --unset name
git config –-system  --unset name

有时候修改的时候会提示找不到修改项

error: key does not contain a section: –-global[local]

可能是文中”–“字符编码的问题,换一种再试

我系统上没有配置系统配置,但是按照一般套路应该是:
系统配置>全局配置>局部配置

所以如果要在不同地址分别配置不同库地址,就不要再设置全局地址,否则会被覆盖(主要是针对图形化的客户端),也比较混乱

Loading Disqus comments...
Table of Contents