Git环境变量
-
linux系统
Git 有三种级别的环境变量,它们分别是: 系统 Git 配置(--system)、当前用户 Git 配置(--global) 和 当前项目 Git 配置(无)。 每一个级别的配置都会覆盖上层的相同配置,即:当前项目配置 > 当前用户配置 > 系统配置
-
windows系统
在 Windows 系统上,Git 会找寻用户主目录下的 .gitconfig 文件 主目录即 $HOME 变量指定的目录,一般都是 C:\\Documents and Settings\\$USER $USER 是当前用户的登录名 此外, Git 还会尝试找寻 Git 安装目录下的 gitconfig 文件
配置Git
-
配置用户信息
可以使用以下命令配置个人的用户名称和电子邮件地址$ git config --global user.name "lik" $ git config --global user.email "likuanhao@126.com"
1、如果用了 -global选项,那么更改的配置文件是位于你用户目录下的那个,以后我们所有的项目都会默认使用这里配置的用户信息
2、如果要配置某个特定的项目中使用其他名字或者邮箱,只要去掉 --global 选项即可 -
配置文本编辑器(了解即可)
我们可以设置 Git 默认使用的文本编辑器
一般情况下可能会配置成 vi 或 vim 当然我们也可以配置成其它的,比如 emacs$ git config --global core.editor emacs
-
配置差异分析工具(了解即可)
差异分析工具是用在解决合并冲突时查看文件差异的
我们可以将默认的差异分析工具改成 vimdiff$ git config --global merge.tool vimdiff
查看配置信息
-
要检查已有的配置信息,可以使用 git config --list 命令
$ git config --list core.symlinks=false core.autocrlf=true core.fscache=true color.diff=auto color.status=auto color.branch=auto color.interactive=true help.format=html rebase.autosquash=true http.sslbackend=openssl http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt credential.helper=manager core.editor="C:\\Program Files (x86)\\Notepad++\\notepad++.exe" -multiInst -notabbar -nosession -noPlugin filter.lfs.clean=git-lfs clean -- %f filter.lfs.smudge=git-lfs smudge -- %f filter.lfs.process=git-lfs filter-process filter.lfs.required=true user.name=lik user.email=likuanhao@126.com
如果看到重复的变量名,那就说明它们来自不同的配置文件(比如 /etc/gitconfig 和 ~/.gitconfig),不过 Git 实际采用的是最后一个
也可以直接查阅某个环境变量的设定,只要把特定的名字跟在后面即可$ git config user.name lik
-
我们也可以直接查看配置文件
比如我们可以用 cat ~/.gitconfig 或 cat /etc/gitconfig 命令查看配置 (linux系统下)
直接找到对应的配置文件打开查看即可(windows系统下)