配置Git¶
概述¶
您的个人Git配置保存在 .gitconfig
在主目录中的文件。
下面是一个例子 .gitconfig
文件:
[user]
name = Your Name
email = you@yourdomain.example.com
[alias]
ci = commit -a
co = checkout
st = status
stat = status
br = branch
wdiff = diff --color-words
[core]
editor = vim
[merge]
summary = true
您可以使用 git config --list
命令。您可以编辑 .gitconfig
或者您可以使用 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
文件,或运行上面的命令。
详细地¶
user.name和user.email¶
告诉别人是个好习惯 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
你的真实姓名和电子邮件地址。
别名¶
您很可能会从一些别名中受益于常用命令。
例如,您可能希望能够缩短 git checkout
到 git co
. 或者你可以化名 git diff --color-words
(它提供了格式良好的diff输出)到 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]
ci = commit -a
co = checkout
st = status -a
stat = status -a
br = branch
wdiff = diff --color-words
花式日志输出¶
这是一个非常好的别名,可以获得奇特的日志输出;它应该 alias
你的部分 .gitconfig
文件:
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)[%an]%Creset' --abbrev-commit --date=relative
使用别名时:
git lg
它提供了这样的图形/文本输出(但有颜色!):
* 6d8e1ee - (HEAD, origin/my-fancy-feature, my-fancy-feature) NF - a fancy file (45 minutes ago) [Matthew Brett]
* d304a73 - (origin/placeholder, placeholder) Merge pull request #48 from hhuuggoo/master (2 weeks ago) [Jonathan Terhorst]
|\
| * 4aff2a8 - fixed bug 35, and added a test in test_bugfixes (2 weeks ago) [Hugo]
|/
* a7ff2e5 - Added notes on discussion/proposal made during Data Array Summit. (2 weeks ago) [Corran Webster]
* 68f6752 - Initial implementation of AxisIndexer - uses 'index_by' which needs to be changed to a call on an Axes object - this is all very sketchy right now. (2 weeks ago) [Corr
* 376adbd - Merge pull request #46 from terhorst/master (2 weeks ago) [Jonathan Terhorst]
|\
| * b605216 - updated joshu example to current api (3 weeks ago) [Jonathan Terhorst]
| * 2e991e8 - add testing for outer ufunc (3 weeks ago) [Jonathan Terhorst]
| * 7beda5a - prevent axis from throwing an exception if testing equality with non-axis object (3 weeks ago) [Jonathan Terhorst]
| * 65af65e - convert unit testing code to assertions (3 weeks ago) [Jonathan Terhorst]
| * 956fbab - Merge remote-tracking branch 'upstream/master' (3 weeks ago) [Jonathan Terhorst]
| |\
| |/
感谢尤里诉扎伊特塞夫的发帖。