git配置git config命令介绍

来源:互联网 发布:淘宝街拍照片如何调色 编辑:程序博客网 时间:2024/05/20 16:00

Git 自带一个 git config的工具来帮助设置控制 Git 外观和行为的配置变量。

git有三个级别的配置文件:

  • system 级别,针对当前电脑的所有用户和所有项目生效,配置文件放在/etc/gitconfig    当用git config --system key value来配置时会修改此文件
  • global级别,针对当前用户的所有项目,配置文件放在用户家目录 ~/.gitconfig  当用git config --global key value来配置时会修改此文件
  • 当前项目级别 只针对当前项目起作用,配置文件放在项目根目下 /path/to/.git/config 当在项目根目录下使用 git config key value来配置时会修改此文件
级别优先级: 当前项目级别 > global > system

  • git config --list  列出当前所有的配置项
  • git config key  列出某个具体的配置项
命令行演示:

[root@localhost ~]# git config --system user.name jerry
[root@localhost ~]# git config --system user.email jerry@example.com
[root@localhost etc]# git config --global user.name global
[root@localhost etc]# git config --global user.email global@example.com
[root@localhost etc]# cat ~/.gitconfig 
[user]
name = global
email = global@example.com
[root@localhost etc]# git config --list
user.name=jerry
user.email=jerry@example.com
user.name=global
user.email=global@example.com
[root@localhost etc]# git config user.email
global@example.com

原创粉丝点击