git config基本篇

來源:互聯網
上載者:User

使用Git的第一件事就是設定你的名字和email,這些就是你在提交commit時的簽名。
樣本1
$ git config --global user.name "Robin Hu"$ git config --global user.email "hudashi@gmail.com"執行了上面的命令後,會在你的主目錄(home directory)建立一個叫~/.gitconfig 的檔案. 內容一般像下面這樣:
[user]name = Robin Huemail = hudashi@gmail.com

git預設的編輯器是GNU nano這樣的編輯器,我可以通過如下的命令把它設定為vim編輯器
樣本2
git config --global core.editor vim我們可以通過git config -h來獲得git config命令的一些基本文法:
 git config -h

usage: git config [options]


Config file location

    --global              use global config file

    --system              use system config file

    --local               use repository config file

    -f, --file <file>     use given config file


Action

    --get                 get value: name [value-regex]

    --get-all             get all values: key [value-regex]

    --get-regexp          get values for regexp: name-regex [value-regex]

    --replace-all         replace all matching variables: name value [value_regex]

    --add                 adds a new variable: name value

    --unset               removes a variable: name [value-regex]

    --unset-all           removes 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            opens an editor

    --get-color <slot>    find the color configured: [default]

    --get-colorbool <slot>

                          find the color setting: [stdout-is-tty]


Type

    --bool                value is "true" or "false"

    --int                 value is decimal number

    --bool-or-int         value is --bool or --int

    --path                value is a path (file or directory name)


Other

    -z, --null            terminate values with NUL byte
   

Git 使用一系列的設定檔來儲存你定義的偏好,它首先會尋找/etc/gitconfig檔案,該檔案含有 對系統上所有使用者及他們所擁有的倉庫都生效的配置值, 如果傳遞--system選項給git config命令, Git 會讀寫這個檔案。

接下來 Git 會尋找每個使用者的~/.gitconfig檔案,你能傳遞--global選項讓 Git讀寫該檔案。

最後 Git 會尋找由使用者定義的各個庫中 Git 目錄下的設定檔(.git/config),該檔案中的值只對該git庫有效。 如果傳遞 --local 選項給git
config命令, Git 會讀寫這個檔案。 --local  選項是預設選項
 以上闡述的三層配置從一般到特殊層層推進,如果定義的值有衝突,以後面層中定義的為準,例如:在.git/config和/etc/gitconfig的較量中, .git/config取得了勝利。雖然你也可以直接手動編輯這些設定檔,但是運行git config命令將會來得簡單些。
-l, --list 用於列出我們已經設定了的git的配置資訊。在
樣本3
 git config --global -l

user.name=Robin Hu

user.email=hudashi@gmail.com

關於git config的更多內容請參考《git
config進階篇》

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.