栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

git config 命令使用

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

git config 命令使用

Git 是分布式版本控制系统,所以,每个机器都必须自报家门:user.name 和 user.email

如果不配置用户信息,是无法进行后续操作的。

全局配置
git config --global user.name "Your username"
git config --global user.email "Your email"

可以用下面的命令为 Git 启用额外的颜色

git config --global color.ui true
局部配置

需要在当前仓库下进行

git config user.name "Your username"
git config user.email "Your email"
git 级别优先级
  1. 仓库级 - local 【最高】
  2. 全局级 - global 【中等】
  3. 系统级 - system 【最低】
全局级配置文件 - global
  1. Linux 的 .gitconfig 文件一般在当前用户主目录 cd ~

  2. Windows 的 .gitconfig 文件路径一般是 C:UsersAdministrator

通过命令查看全局级配置文件:git config --global -l

仓库级配置文件 - local

Git 仓库级配置文件都在当前仓库下的 .git/config 里面

Windows 中的 .git 文件是隐藏的,需要在文件管理器中勾选【隐藏的项目】

通过命令查看仓库级配置文件:git config --local -l

系统级配置文件 - system

Git 系统级配置文件都 Git 安装目录下的 /etc/gitconfig 里面

通过命令查看系统级配置文件:git config --system -l

查看配置文件

命令参数:–list

简写:-l

格式:git config [–local | --global | --system] -l

  • 仓库级 config:git config --local -l
  • 全局级 config:git config --global -l
  • 系统级 config:git config --system -l
  • 当前生效的配置:git config -l
编辑配置文件

命令参数:–edit

简写:-e

格式:git config [–local | --global | --system] -e

  • 仓库级 config:git config --local -e
  • 全局级 config:git config --global -e
  • 系统级 config:git config --system -e
  • 默认编辑仓库级 config:git config -e

使用 :q 来退出编辑器

注:执行这个命令的时候,Git 会用配置文件中设定的编辑器打开配置文件

增加配置项

命令参数:–add

格式:git config [–local | --global | --system] --add section.key value

  • 默认是添加在 local 配置文件,且 section,key,value 一项都不能少

例如我们执行命令:git config --global --add idol.name Liyuu 就能够给全局级配置文件中添加配置项

获取配置项

命令参数:–get

格式:git config [–local | --global | --system] --get section.key

  • 默认是获取 local 配置文件里的配置项

  • 直接使用 git config section.key 省略 --get 也可以

  • 如果获取一个 section 不存在的 key,不会返回任何值

  • 如果获取一个不存在的 section 的 key,会报错

删除配置项

命令参数:–unset

格式:git config [–local | --global | --system] --unset section.key

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/288718.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号