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

查看配置 git config

  • 查看全部的設置
git config list

或者

git config -l
  • 查看選項配置 git config -l ,選項參數linux

  • --system: 系統配置(全部git帳戶)git

  • --global: 全局配置(一個用戶)vim

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

只能在項目目錄下,使用 --local ,讀取的是 .git/config編輯器

優先級:由高到低工具

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

如:查看全局配置選項命令:ui

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

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

git config -l --system

不帶參數-l, 默認是項目的配置(--local);參數順序可先可後code

修改配置

和上面查看同樣,只不過參數由 -l(list) 變成 -e (edit)orm

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

不帶參數-l, 默認是項目的配置(--local);參數順序可先可後it

配置文件的位置

  • 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  'xxxx@qq.com'

其餘:

//設置編輯器,默認是 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 alias.別名名