Git的配置


2.1、查看配置

git config -l 查看詳細配置

image

查看不同級別的配置文件:

#查看系統config
git config --system --list
  
#查看當前用戶(global)配置
git config --global  --list
 
#查看當前倉庫配置信息
git config --local  --list

2.2、Git配置文件分類

Git相關的配置文件有三個:

1)、 /etc/gitconfig:包含了適用於系統所有用戶和所有項目的值。注是git的安裝目錄(Win:D:\Git\mingw64\etc\gitconfig) --system 系統級

image

2)、~/.gitconfig:只適用於當前登錄用戶的配置。(Win:C:\Users\Administrator.gitconfig) --global 全局

image

3)、位於git項目目錄中的.git/config:適用於特定git項目的配置。--local當前項目

image

注意:對於同一配置項,三個配置文件的優先級是1<2<3

2.3、設置用戶名與郵箱(用戶標識,必要)

當你安裝Git后首先要做的事情是設置你的用戶名稱和e-mail地址。這是非常重要的,因為每次Git提交都會使用該信息。它被永遠的嵌入到了你的提交中:

	$ git config --global user.name "***"  #名稱
 	$ git config --global user.email ****@qq.com   #郵箱

只需要做一次這個設置,如果你傳遞了--global 選項,因為Git將總是會使用該信息來處理你在系統中所做的一切操作。如果你希望在一個特定的項目中使用不同的名稱或e-mail地址,你可以在該項目中運行該命令而不要--global選項。 總之--global為全局配置,不加為某個項目的特定配置。修改如上圖2所示;

2.4、添加或刪除配置項

1)、添加配置項

git config [--local|--global|--system]  section.key value

[--local|--global|--system]  #可選的,對應本地,全局,系統不同級別的設置
section.key #區域下的鍵
value #對應的值
--local 項目級
--global 當前用戶級
--system 系統級 

2)、刪除配置項

git config [--local|--global|--system] --unset section.key

2.5、更多配置項

git config --global color.ui true   #打開所有的默認終端着色
git config --global alias.ci commit   #別名 ci 是commit的別名
[alias]  
co = checkout  
ci = commit  
st = status  
pl = pull  
ps = push  
dt = difftool  
l = log --stat  
cp = cherry-pick  
ca = commit -a  
b = branch 

user.name  #用戶名
user.email  #郵箱
core.editor  #文本編輯器  
merge.tool  #差異分析工具  
core.paper "less -N"  #配置顯示方式  
color.diff true  #diff顏色配置  
alias.co checkout  #設置別名
git config user.name  #獲得用戶名
git config core.filemode false  #忽略修改權限的文件  

所有config命令參數

語法: git config [<options>]        
        
文件位置        
    --global                  #use global config file 使用全局配置文件
    --system                  #use system config file 使用系統配置文件
    --local                   #use repository config file    使用存儲庫配置文件
    -f, --file <file>         #use given config file    使用給定的配置文件
    --blob <blob-id>          #read config from given blob object    從給定的對象中讀取配置
        
動作        
    --get                     #get value: name [value-regex]    獲得值:[值]名[正則表達式]
    --get-all                 #get all values: key [value-regex]    獲得所有值:[值]名[正則表達式]
    --get-regexp          #get values for regexp: name-regex [value-regex]    得到的值根據正則
    --get-urlmatch            #get value specific for the URL: section[.var] URL    為URL獲取特定的值
    --replace-all             #replace all matching variables: name value [value_regex]    替換所有匹配的變量:名稱值[ value_regex ]
    --add                     #add a new variable: name value    添加一個新變量:name值
    --unset                   #remove a variable: name [value-regex]    刪除一個變量名[值]:正則表達式
    --unset-all               #remove all matches: name [value-regex]    刪除所有匹配的正則表達式:名稱[值]
    --rename-section          #rename section: old-name new-name    重命名部分:舊名稱 新名稱
    --remove-section          #remove a section: name    刪除部分:名稱
    -l, --list                #list all    列出所有
    -e, --edit            #open an editor    打開一個編輯器
    --get-color               #find the color configured: slot [default]    找到配置的顏色:插槽[默認]
    --get-colorbool           #find the color setting: slot [stdout-is-tty]    發現顏色設置:槽[ stdout是TTY ]
        
類型        
    --bool                    #value is "true" or "false"    值是“真”或“假”。
    --int                     #value is decimal number    值是十進制數。
    --bool-or-int             #value is --bool or --int    值--布爾或int
    --path                    #value is a path (file or directory name)    值是路徑(文件或目錄名)
        
其它        
    -z, --null                #terminate values with NUL byte    終止值與null字節
    --name-only               #show variable names only    只顯示變量名
    --includes                #respect include directives on lookup    尊重包括查找指令
    --show-origin             #show origin of config (file, standard input, blob, command line)    顯示配置(文件、標准輸入、數據塊、命令行)的來源


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM