分享

git config命令使用第二篇——增加删除section操作 转

 ala咪s 2017-04-24
date_dir=$(date +%Y%m%d%H%M)
   mkdir -p `pwd`/${date_dir}
   cd `pwd`/${date_dir}
   git init
   git remote add origin_${repository_name} ssh://gerritroot@${server_ip}:29418/${repository_name}
   git fetch origin_${repository_name} refs/meta/config:config_${repository_name}
   git checkout config_${repository_name}
   echo -e "${uuid_write}\0011${write_group}" >>groups
   echo -e "${uuid_submit}\0011${submit_group}" >>groups
   echo -e "${uuid_admin}\0011Administrators" >>groups
   git config -f project.config access."refs/*".read "group Administrators" --add
   git config -f project.config access."refs/*".read "group ${write_group}" --add
   git config -f project.config access."refs/*".read "group ${submit_group}" --add
   git config -f project.config access."refs/for/refs/*".push "group Administrators" --add
   git config -f project.config access."refs/for/refs/*".push "group ${write_group}" --add
 
 

1. 删除一个section

命令参数 --remove-section

格式:git config [--local|--global|--system] --remove-section section

使用这个命令,不仅可以删除一个没有内容的section,而且即使该section下面有内容,也会一起删除掉

比如我们来删除这样一个配置:



直接使用命令: git config --local --remove-section dog,这样可以把dog下面的内容全部删除,而且也能删除掉section

2. 查看value类型

一共可以查看四种类型:--bool, --int, --bool-or-int, --path

格式:git config [--local|--global|--system] [--bool|--int|--bool-or-int|--path] section.key

使用示例:git config --local --bool dog.name

如果dog.name不是布尔值,且也不能被转化为bool值,那么git就会报错;否则git会显示true或false 

3. 操作特殊的section

看看这类sectino长什么样子的

这类section后面还跟了一个字段,例如[remote "origin"]

对这类section应该如何使用git config进行操作呢?很简单把section后面的字段也作为section的key写进去,这样会多一层嵌套,但是忽略了这一层就会报错了

比如我们要对[remote "master"]下的url做修改,git config --local remote.origin.url  value,value为修改后的值,这样就ok啦,而增删改查都是一样的

4. 重命名section

参数:--rename-section

格式:git config [--local|--global|--system] --rename-section section1 section2

比如我们把名为dog的section改为dog1, git config --local rename-section dog dog1,这样就好咯

5. 替换,获取和删除多个属性

参数:--replace-all, --get-all, -unset-all

如果此时,配置中有,dog.a=dddd,同时还有dog.a = aaaa,如下图

然后,可以对这些进行修改, git config --local --replace-all dog.a 333

这时候dog.a值均被替换,且只保留最后一个,这个是需要注意的

获取配置中所有dog.a的value值

删除配置中所有dog.a的value值

6. 运用正则初步

参数: --replace-all, --get-regexp

正则很强大,同样的,在git中也很强大,git中并没有专门的获取某个section下面所有key值value的方法,但是试用--get-regexp这个参数就可以实现

例如我们来获取配置中的core下面的所有key值的value

使用命令:get config --local --get-regexp core 即可

--replace-all中也可以使用正则的

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多