Git 筆記 (2-1) Git Configuration

Git 筆記


Git configuration的設定檔,下面的優先權 1 > 2 > 3:

1. .git 中的 config: 這個設定檔對所在的檔案庫有效

2. ~ 下的 .gitconfig: 這個設定檔對該使用者有效

3. etc 下的 gitconfig: 這個設定檔對該系統的使用者有效


下表為 git config 常用的選項,通常會穿插 --local, --global, --system:

選項Description
-l用來顯示所有層級的 configuration
user.xxx設定 [user] 底下的屬性,和使用者的資訊有關
alias.xxx設定 [alias] 底下的屬性,和 command 的別名有關
core.xxx設定 [core] 底下的屬性,和 git 系統的設定有關
diff.xxx設定 [diff] 底下的屬性,和比較檔案差異有關


如何查看上面 1 2 3 點的 git configuration?

$ git config --local -l
$ git config --global -l
$ git config --system -l

如果沒有該檔案的話,終端機會顯示他所查找的路徑及設定檔名稱


如何設定的 git configuration?

這邊以設定 global (~/.gitconfig) 的 configuration file 為範例:

$ git config --global user.name "ooxx"
$ git config --global user.email "ooxx@gmail.com"

若設定成功會發現 .gitconfig 多了 [user] 底下定義了 name

其他層級也是依此類推


如何刪除 git configuration 設定的過的選項?

這邊以刪除 global (~/.gitconfig) 的 user.name 為範例:

$ git config --unset --global user.name

如何設定 git alias?

這邊以設定 alias.con 為範例,將 alias.con 加入 config:

$ git config alias.con "config -l"

若設定成功會發現 config 多了 [alias] 底下定義了 con

使用 git 的 alias:

$ git con

如何設定 git 的預設編輯器?

這邊以 notepad 作為預設編輯器:

$ git config --global core.editor notepad

如何設定 git 的預設比較器?

這邊以 kdiff3 作為預設編輯器:

$ git config --global diff.tool kdiff3

留言

熱門文章