你个人 git 配置保存在 .gitconfig 在主目录中的文件。下面是一个例子 .gitconfig 文件::
.gitconfig
[user] name = Your Name email = you@yourdomain.example.com [alias] ci = commit -a co = checkout st = status -a stat = status -a br = branch wdiff = diff --color-words [core] editor = vim [merge] summary = true
您可以直接编辑此文件,也可以使用 git config --global 命令:
git config --global
git config --global user.name "Your Name" git config --global user.email you@yourdomain.example.com git config --global alias.ci "commit -a" git config --global alias.co checkout git config --global alias.st "status -a" git config --global alias.stat "status -a" git config --global alias.br branch git config --global alias.wdiff "diff --color-words" git config --global core.editor vim git config --global merge.summary true
要在另一台计算机上设置,可以复制 ~/.gitconfig 文件,或运行上面的命令。
~/.gitconfig
告诉别人是个好习惯 git 您是谁,用于标记对代码所做的任何更改。最简单的方法是从命令行:
git config --global user.name "Your Name" git config --global user.email you@yourdomain.example.com
这将把设置写入Git配置文件,该文件现在应该包含一个用户名和电子邮件的用户部分:
[user] name = Your Name email = you@yourdomain.example.com
当然,你需要更换 Your Name 和 you@yourdomain.example.com 你的真实姓名和电子邮件地址。
Your Name
you@yourdomain.example.com
您很可能会从一些别名中受益于常用命令。
例如,您可能希望能够缩短 git checkout 到 git co . 或者你可以化名 git diff --color-words (它提供了格式良好的diff输出)到 git wdiff
git checkout
git co
git diff --color-words
git wdiff
以下 git config --global 命令:
git config --global alias.ci "commit -a" git config --global alias.co checkout git config --global alias.st "status -a" git config --global alias.stat "status -a" git config --global alias.br branch git config --global alias.wdiff "diff --color-words"
将创建一个 alias 在你的章节 .gitconfig 包含如下内容的文件:
alias
[alias] ci = commit -a co = checkout st = status -a stat = status -a br = branch wdiff = diff --color-words
您可能还希望确保使用您选择的编辑器:
git config --global core.editor vim
执行合并时强制执行摘要 (~/.gitconfig 再次提交文件:
[merge] log = true
或者从命令行:
git config --global merge.log true