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 (差分をきれいにフォーマットして出力します)を 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"

.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

凝ったログ出力#

これは、凝ったログ出力を取得するための非常に優れたエイリアスです。これは、.gitconfig ファイルの alias セクションに入れる必要があります。

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]
| |\
| |/

投稿してくれた Yury V. Zaytsev に感謝します。