Git config

描述:

git config命令用於獲取並設置存儲庫或全局選項。
Git 自帶一個 git config 的工具來幫助設置控制 Git 外觀和行爲的配置變量。 這些變量存儲在三個不同的位置:

  • --global:~/.gitconfig 或 ~/.config/git/config,只針對當前用戶。
  • --system:/etc/gitconfig,Windows在Git安裝目錄mingw64/etc/下
  • --local: 當前Git倉庫 .git/config

注意: 每一個級別覆蓋上一級別的配置,所以 .git/config 的配置變量會覆蓋 /etc/gitconfig 中的配置變量。

常用命令:

  • 配置用戶信息
    git config --global user.name "you name"
    git config user.email "you email"

    注意: 如果使用了 --global 選項,那麼該命令只需要運行一次,因爲之後無論你在該系統上做任何事情, Git 都會使用那些信息。 當你想針對特定項目使用不同的用戶名稱與郵件地址時,可以在那個項目目錄下運行沒有 --global 選項的命令來配置。

  • 配置編輯器
    git config --global core.editor <editor>

    注意: 配置默認的編輯器,Windows可以是一個路徑用於指定編輯器, 像這樣 :
    git config --global core.editor "'C:/Program Files/Sublime Text 3/subl.exe' -n -w"
    其中 -n 表示在一個新窗口啓動編輯器,-w 表示命令行將等待直到保存並關閉提交消息。更多內容請閱讀這裏

  • 配置比較工具
    git config --global merge.tool <merge tool>

    注意: Git可以接受 kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, 和 opendiff 作爲有效的合併工具。也可以設置一個客戶端的工具。

  • 檢查配置
    git config --list

  • 配置別名(快捷方式)
    git config --global alias.<alias> <command>

    注意: 有參數的命令需要使用雙引號

  • 刪除別名
    git config [--global] --unset alias.<alias>

其他:

  • 添加配置
    git config [–local|–global|–system] –add section.key value

  • 刪除配置
    git config [–local|–global|–system] –unset section.key

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章