設定 git#
概觀#
您的個人 git 設定會儲存在您 home 目錄中的 .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 Name
和 you@yourdomain.example.com
替換為您的實際姓名和電子郵件地址。
別名#
您可能會從一些常用命令的別名中受益。
例如,您可能希望能夠將 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"
將在您的 .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 發布此內容。