天天看點

git--修改使用者名和郵箱的方法(全局修改和局部修改)

簡介

        本文介紹如何修改git的使用者名和郵箱,包括:如何全局修改使用者名和郵箱,如何隻修改某個項目的使用者名和密碼)。

        如果配置了局部的使用者名和郵箱,則會優先使用局部的;如果沒有配置局部的使用者名和郵箱,則會使用全局的。

修改方法

全局修改

git config --global user.name "Tony"
git config --global user.email "[email protected]"      

修改完後,會自動在 C:\Users\xxx\.gitconfig檔案添加如下内容:

[user]
    name = Tony
    email = [email protected]      

局部修改

        有時候,我們想在某個項目裡用其他的使用者名。比如:在公司裡時,有時會修改個人的代碼然後送出,想用單獨的使用者名,不跟公司的項目一樣。

git config user.name "Tony"
git config user.email "[email protected]"      

修改完後,會自動在 (目前目錄).git/config檔案添加如下内容:

[user]
    name = Tony
    email = [email protected]      

git配置詳述

配置方法

指令 作用 示例
git config [配置儲存位置] [配置項] [配置值] 将某個配置項設定為指定值。

例:設定送出代碼時的名字和郵箱。

git config --global user.name "Tony"

git config --global user.email "[email protected]"

[name]和[email address]加不加引号都可以。

這兩項不會用于資訊驗證,可任意設定。

若郵箱與賬号郵箱一樣,則commits顯示此郵箱的賬号。

git config -l [配置儲存位置]

//git config --list [配置儲存位置]

顯示目前配置。(按q鍵退出)
git config -e [配置儲存位置] 用vi編輯.git/conf檔案。

配置儲存位置

英文 含義 配置儲存檔案 示例
--local 本地配置。預設 (目前目錄).git/config

以user.name和user.email為例:

git config --local user.name "Tony"

git config --local user.email "[email protected]"

配置完後,會在.git/config生成如下内容:

[user]

    name = Tony

    email = [email protected]

--global 目前使用者(全局) C:\Users\xxx\.gitconfig
--system 所有使用者(本系統) $(prefix)/etc/gitconfig
--worktree 類似于--local 如果extensions.worktreeConfig存在,則讀寫.git/config.worktree。否則跟--local一樣。

取消配置

指令 作用 示例
git config [配置儲存位置] --unset [配置項] 删除某個配置。