1. 程式人生 > >【git配置】配置詳解&快捷命令(自定義短命令)

【git配置】配置詳解&快捷命令(自定義短命令)

開發十年,就只剩下這套架構體系了! >>>   

檢視配置 git config

  • 檢視所有的設定
git config list

或者

git config -l
  • 檢視選項配置 git config -l ,選項引數

  • --system: 系統配置(所有git賬戶)

  • --global: 全域性配置(一個使用者)

  • --local: 專案[本地]配置(一個專案), 或者叫倉庫配置

只能在專案目錄下,使用 --local ,讀取的是 .git/config

優先順序:由高到低

git config > git config --global > git config --system

如:檢視全域性配置選項命令:

git config -l --global 或 git config --global -l

git config -l 或者 git config -l --local

git config -l --system 

不帶引數-l, 預設是專案的配置(--local);引數順序可先可後

修改配置

和上面檢視一樣,只不過引數由 -l(list) 變成 -e (edit)

git config -e --global
git config -e --system
git config -e --local 或者 git config -e

不帶引數-l, 預設是專案的配置(--local);引數順序可先可後

配置檔案的位置

  • system: 在git 工具的安裝目錄下

如:F:\devTools\Git\etc\gitconfig

  • global: 在系統盤,宿主目錄下. ~/.gitconfig

如: C:\Users\laozhongyi.gitconfig

  • local: 在專案下的目錄中, ./git/config

如: /專案目錄/.git/config

設定資訊

  • 方法1: 使用上面的修改命令,git config -e
  • 方法2: 單獨設定 如:設定使用者資訊
git config --global user.name  'xxxx'
git config  --global user.email  '[email protected]'

其他:

//設定編輯器,預設是 vi  vim 
git config --global core.editor sublime

//顯示顏色
git config --global color.ui true

//設定比較工具
git config --global merge.tool vimdiff
注:Git可以接受kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, 和 
opendiff作為有效的合併工具。你也可以設定一個客戶化的工具

單獨檢視某一項的配置

git config user.name

git alias [ˈeɪliəs] 的使用

設定方法

  • 設定方法1. git config --global alias.快捷名 命令名

如:

git config --global alias.s status

使用:git s

  • 設定方法2. 直接在配置檔案 ~/.gitconfig 中新增,修改

  • 設定方法3.

如果我們想要命令更簡單,如 git s -> gits, 就可以linux系統中新增alias了,在檔案~/.bashrc 中

如:

alias gs='git status'
alias gc='git commit -m '
alias gaa= 'git add .'
alias gp='git push'
alias gl='git log --graph'

命令新增後,讓修改的檔案立即生效,使用命令 source ~/.bashrc 或者 . ~/.bashrc

應用:美化git log

在配置檔案 \Git\etc\bash.bashrc 中新增以下命令即可

alias gl="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"

刪除方法

git config --global --unset alia