git 配置文件位置;git配置文件設置


一. 配置文件的存儲位置

Git相關的配置文件有三個

1. /etc/gitconfig:包含了適用於系統所有用戶和所有項目的值。

2.~/.gitconfig:只適用於當前登錄用戶的配置。

3. 位於git項目目錄中的.git/config:適用於特定git項目的配置。

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


二. 一些有用的配置項

1. 設置別名

[alias] 為git命令配置別名

例:

[plain]  view plain   copy
  1. [alias]  
  2.     st = status  
  3.     ci = commit  
  4.     br = branch   

當你有了上述配置后,使用git st等同於使用git stauts


甚至有人喪心病狂的 設置 git lg 這種快捷方式:

git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
這樣 git lg ,實際執行的是“
git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
”,效果還是不錯的。


2. 輸出顏色

[color] 設置git輸出着色

例:

[plain]  view plain   copy
  1. [color]  
  2.     ui = true  

設置color.ui為true來打開所有的默認終端着色。

對比一下,無此配置時

加入配置后



3. core.filemode 讓git忽略對文件權限的修改

[plain]  view plain   copy
  1. [core]  
  2.     filemode = false  

4.使用vimdiff呈現Git diff差異

[plain]  view plain   copy
  1. [diff]  
  2.     tool = vimdiff  
  3. [difftool]  
  4.     prompt = false  
  5. [alias]  
  6.     d = difftool  
使用時只需將用到git diff的地方換為git d就可以了。


三. 用git config操作配置文件

1. 列出當前配置項

git config [–system|–global|–local] -l
使用system, golbal, local時,分別列出對應一部分中的1,2,3三個文件之一的配置項。
如果不加上述三個選項,則會按一部分中所說的優先級合並所有配置項並輸出。

2.添加配置項 

git config [–local|–global|–system]  section.key value
例:
[plain]  view plain   copy
  1. git config core.filemode true   
執行后會在配置文件中添加 
[plain]  view plain   copy
  1. [core]  
  2.     filemode = true  

3.刪除配置項

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


免責聲明!

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



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