安装 Git 后,需要先进行下简单的配置。每台计算机上只需要配置一次,程序升级时会保留配置信息。你可以在任何时候再次通过运行命令来修改它们。
Git自带一个 git config
的工具来帮助设置控制Git外观和行为的配置变量。这些变量存储在三个不同的位置:
/etc/gitconfig
文件: 包含系统上每一个用户及他们仓库的通用配置。 如果使用带有 --system
选项的 git config
时,它会从此文件读写配置变量。
~/.gitconfig
或 ~/.config/git/config
文件:只针对当前用户。 可以传递 --global
选项让 Git 读写此文件。.git/config
):针对该仓库。每个级别会覆盖上一级的配置,例如 .git/config
的配置变量会覆盖 /etc/gitconfig
中的配置变量
首先需要设置的是用户名和邮箱地址。这两个信息会被写入每一次的提交中,不可更改。
通过 git config
工具来设置,如果添加了 --global
选项,那么下面的命令只需要执行一次,系统会默认使用这些信息。如果在某个具体的项目中使用不同的用户名和邮箱,可以重新执行不带有 --global
选项 的命令。
git config --global user.name "w1nww"
git config --global user.email w1nww@xiuyetang.com
在 Git 中通常需要会需要执行一些文本操作,你可以配置你习惯的文本编辑器。如果不配置,通常默认为vim
。
git config --global core.editor emacs
上面这段命令就是配置编辑器为 emacs。
可以查看下当前的所有 Git 配置:
git config --list
我本机的配置如下:
credential.helper=osxkeychain
user.name=zhusandiao
user.email=zhusandiao@gmail.com
core.excludesfile=/Users/abc/.gitignore_global
difftool.sourcetree.cmd=opendiff "$LOCAL" "$REMOTE"
difftool.sourcetree.path=
mergetool.sourcetree.cmd=/Applications/SourceTree.app/Contents/Resources/opendiff-w.sh "$LOCAL" "$REMOTE" -ancestor "$BASE" -merge "$MERGED"
mergetool.sourcetree.trustexitcode=true
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
core.precomposeunicode=true
remote.origin.url=git@121.40.31.31:zzl005/xyt.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
remote.origin.pushurl=git@121.40.31.31:zzl005/xyt.git
branch.master.remote=origin
branch.master.merge=refs/heads/master
remote.adamorigin.url=git@121.40.31.31:adam/xyt.git
remote.adamorigin.fetch=+refs/heads/*:refs/remotes/adamorigin/*
如果你只想检查某个 Git 的某个具体的配置,可以执行 git config <key>
比如,我想看看当初设定的邮箱是什么,就可以执行下面这段
相关文章推荐: