配置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 --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 Nameyou@yourdomain.example.com 写上你的真实姓名和电子邮件地址。

别名

您可能会从常用命令的一些别名中获益。

例如,您很可能希望能够缩短 git checkoutgit 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

编辑

您可能还希望确保使用您选择的编辑器:

git config --global core.editor vim

合并中

要在执行合并时强制执行汇总,请执行以下操作 (~/.gitconfig 再次文件)::

[merge]
   log = true

或从命令行::

git config --global merge.log true

花式原木输出

这是一个非常好的别名,可以获得漂亮的日志输出;它应该放在 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 implimentation 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]
| |\
| |/

感谢Yury V.Zaytsev发布了这篇文章。