網站首頁 編程語言 正文
1、配置Git簽名
(1)語法
$ git config 配置文件作用域 user.name '用戶名' $ git config 配置文件作用域 user.email '郵箱地址'
示例如下:
配置 user.name和user.email |
---|
$ git config --global user.name ‘your_name' |
$ git config --global user.email ‘your_email@domain.com' |
注意:這個email
一定是有效的,是你能夠收得到郵件的email
。
(2)配置系統用戶簽名
可在任意目錄下運行創建命令:git config --system
L@DESKTOP-T2AI2SU MINGW64 /j/git-repository/learngit $ git config --system user.name 'tang_s' L@DESKTOP-T2AI2SU MINGW64 /j/git-repository/learngit $ git config --system user.email 'tang_s@126.com'
提示:在Git中,沒有提示就是最好的提示。
系統用戶注冊信息會寫在本地Git的安裝目錄下,...\etc\gitconfig
文件中。
L@DESKTOP-T2AI2SU MINGW64 /j/git-repository/learngit $ cat /f/DevInstall/Git/GitforWindows/etc/gitconfig [diff "astextplain"] textconv = astextplain [filter "lfs"] clean = git-lfs clean -- %f smudge = git-lfs smudge -- %f process = git-lfs filter-process required = true [http] sslBackend = openssl sslCAInfo = F:/DevInstall/Git/GitforWindows/mingw64/ssl/certs/ca-bundle.crt [core] autocrlf = true fscache = true symlinks = false [credential] helper = manager [user] name = tang_s email = tang_s@126.com
提示:之前的Git版本中,gitconfig
文件是在,Git安裝目錄下mingw64
目錄中的etc/gitconfig
。
(3)配置全局用戶簽名
可在任意目錄下運行創建命令:git config --global
# 在任何位置執行都可以 # 執行這個配置表示你這臺機器上所有的Git倉庫都會使用這個配置, # 當然也可以對某個倉庫指定不同的用戶名和Email地址(本地用戶)。 L@DESKTOP-T2AI2SU MINGW64 /j/git-repository/learngit $ git config --global user.name 'sun_wk' L@DESKTOP-T2AI2SU MINGW64 /j/git-repository/learngit $ git config --global user.email 'sun_wk@126.com'
全局用戶注冊的信息,會寫到當前用戶目錄下.gitconfig
文件中。
L@DESKTOP-T2AI2SU MINGW64 /j/git-repository/learngit $ cat /c/Users/L/.gitconfig [user] name = sun_wk email = sun_wk@126.com
(4)配置本地用戶簽名
本地庫用戶只能在當前的本地庫目錄下運行該命令:
# 注意如果是配置local配置文件簽名,可以省略--local參數 $ git config --local user.name 'sha_hs' $ git config --local user.email 'sha_hs@126.com'
注意:
執行上邊命令,要在一個倉庫中執行,否則會提示你:
fatal: --local can only be used inside a git repository
還有
--local
選項只能在Git倉庫中使用。
演示:
# 此時learngit目錄不是一個本地Git倉庫 L@DESKTOP-T2AI2SU MINGW64 /j/git-repository/learngit $ git config --local user.name '' fatal: --local can only be used inside a git repository # 初始化learngit目錄為Git本地倉庫 L@DESKTOP-T2AI2SU MINGW64 /j/git-repository/learngit $ git init Initialized empty Git repository in J:/git-repository/learngit/.git/ L@DESKTOP-T2AI2SU MINGW64 /j/git-repository/learngit (master) # 配置本地用戶簽名 L@DESKTOP-T2AI2SU MINGW64 /j/git-repository/learngit (master) $ git config --local user.name 'sha_hs' L@DESKTOP-T2AI2SU MINGW64 /j/git-repository/learngit (master) $ git config --local user.email 'sha_hs@126.com'
本地用戶注冊信息,會寫到當前版本庫目錄下的.git
目錄中的config
文件中。
L@DESKTOP-T2AI2SU MINGW64 /j/git-repository/learngit (master) $ cat .git/config [core] repositoryformatversion = 0 filemode = false bare = false logallrefupdates = true symlinks = false ignorecase = true [user] name = sha_hs email = sha_hs@126.com
注意:
- 簽名設置的用戶名和郵箱,主要作用就是區分不同開發人員的身份。
- 這里設置的簽名和登錄遠程庫,也就是代碼托管中心的賬號、密碼沒有任何關系。
- Email地址沒有要求和用戶名一致,甚至Email地址不存在都沒事。
- 但是在實際工作中,這個Email一定是有效的,是你能夠收得到郵件的Email。
2、查看三個配置文件的用戶簽名
通過命令的方式查看三個配置文件的用戶簽名。
(1)語法
執行git config
命令,來查看各作用域配置文件中的配置信息。(這個命令在任何路徑下都能執行)
只執行git config
命令,會顯示git config
命令所有的可用參數。
執行git config --list
命令,查看當前系統中Git的所有配置,三個配置文件所有的配置都顯示出來。
查看指定指定配置文件的內容:
執行語句 | 說明 |
---|---|
$ git config --list --local | 查看項目/倉庫級別的配置文件信息 |
$ git config --list --global | 查看用戶級別配置文件信息 |
$ git config --list --system | 查看系統級別配置文件信息 |
(2)查看項目/倉庫級別的配置文件信息(local)
需要進入到一個倉庫中,執行$ git config --list --local
命令,才能顯示該倉庫的配置信息。否則會出現提示
fatal: --local can only be used inside a git repository,
--local
選項只能在Git倉庫中使用。
L@DESKTOP-T2AI2SU MINGW64 /j/git-repository $ git config --list --local fatal: --local can only be used inside a git repository L@DESKTOP-T2AI2SU MINGW64 /j/git-repository $ cd learngit/ L@DESKTOP-T2AI2SU MINGW64 /j/git-repository/learngit (master) $ git config --list --local core.repositoryformatversion=0 core.filemode=false core.bare=false core.logallrefupdates=true core.symlinks=false core.ignorecase=true user.name=sha_hs user.email=sha_hs@126.com
提示:
執行$ git config --list --local
命令時, Git會讀取倉庫中.git
目錄下的.git/config
配置文件,該文件含有當前倉庫的配置信息。
# 查看.git目錄 L@DESKTOP-T2AI2SU MINGW64 /j/git-repository/learngit (master) $ ll .git/ total 7 -rw-r--r-- 1 L 197121 176 4月 2 22:43 config -rw-r--r-- 1 L 197121 73 4月 2 22:41 description -rw-r--r-- 1 L 197121 23 4月 2 22:41 HEAD drwxr-xr-x 1 L 197121 0 4月 2 22:41 hooks/ drwxr-xr-x 1 L 197121 0 4月 2 22:41 info/ drwxr-xr-x 1 L 197121 0 4月 2 22:41 objects/ drwxr-xr-x 1 L 197121 0 4月 2 22:41 refs/ # 查看.git/config文件中的內容 L@DESKTOP-T2AI2SU MINGW64 /j/git-repository/learngit (master) $ cat .git/config [core] repositoryformatversion = 0 filemode = false bare = false logallrefupdates = true symlinks = false ignorecase = true [user] name = sha_hs email = sha_hs@126.com
(3)查看用戶/全局級別的配置文件信息(global)
在任何位置執行$ git config --list --global
命令即可。
# 任何目錄下執行都可以 L@DESKTOP-T2AI2SU MINGW64 /j/git-repository/learngit (master) $ git config --list --global user.name=sun_wk user.email=sun_wk@126.com
注意:
如果我們是新安裝的Git,還沒有配置過global
作用域內的配置信息,global
級別的配置文件是沒有的,只有我們配置一次global
級別的配置信息,配置文件才會生成。
fatal: unable to read config file 'C:/Users/L/.gitconfig': No such file or directory
提示你無法讀取配置文件'C:/Users/L/.gitconfig'
:沒有此類文件或目錄。
提示:
當我們配置過global
作用域中的信息后,C:/Users/L/
中的.gitconfig
文件出現了。
執行git config --list --global
命令后,查看的就是C:/Users/L/.gitconfig
文件中的內容。
(4)查看系統級別的配置文件信息(system)
在任何位置執行$ git config --list --system
命令即可。
演示:
L@DESKTOP-T2AI2SU MINGW64 /j/git-repository $ git config --list --system diff.astextplain.textconv=astextplain filter.lfs.clean=git-lfs clean -- %f filter.lfs.smudge=git-lfs smudge -- %f filter.lfs.process=git-lfs filter-process filter.lfs.required=true http.sslbackend=openssl http.sslcainfo=F:/DevInstall/Git/GitforWindows/mingw64/ssl/certs/ca-bundle.crt core.autocrlf=true core.fscache=true core.symlinks=false credential.helper=manager user.name=tang_s user.email=tang_s@126.com
提示:
該命令讀取的配置文件所在的位置是,Git安裝目錄下的etc
目錄中的gitconfig
文件。
查看gitconfig
文件中的內容,與上邊顯示的內容是對應的。
(5)查看當前系統中Git的所有配置信息
執行git config --list
命令,查看當前系統中Git的所有配置,上面三個配置文件所有的配置都顯示出來。
示例:
# 如果沒有再本地倉庫中執行該命令,只顯示系統用戶和全局用戶配置文件中的信息 L@DESKTOP-T2AI2SU MINGW64 /j/git-repository $ git config --list diff.astextplain.textconv=astextplain filter.lfs.clean=git-lfs clean -- %f filter.lfs.smudge=git-lfs smudge -- %f filter.lfs.process=git-lfs filter-process filter.lfs.required=true http.sslbackend=openssl http.sslcainfo=F:/DevInstall/Git/GitforWindows/mingw64/ssl/certs/ca-bundle.crt core.autocrlf=true core.fscache=true core.symlinks=false credential.helper=manager user.name=tang_s # 系統用戶簽名 user.email=tang_s@126.com user.name=sun_wk # 全局用戶簽名 user.email=sun_wk@126.com # 如果在本地倉庫中執行該命令,三種用戶配置文件的信息都會顯示出來 L@DESKTOP-T2AI2SU MINGW64 /j/git-repository $ cd learngit/ L@DESKTOP-T2AI2SU MINGW64 /j/git-repository/learngit (master) $ git config --list diff.astextplain.textconv=astextplain filter.lfs.clean=git-lfs clean -- %f filter.lfs.smudge=git-lfs smudge -- %f filter.lfs.process=git-lfs filter-process filter.lfs.required=true http.sslbackend=openssl http.sslcainfo=F:/DevInstall/Git/GitforWindows/mingw64/ssl/certs/ca-bundle.crt core.autocrlf=true core.fscache=true core.symlinks=false credential.helper=manager user.name=tang_s # 系統用戶簽名 user.email=tang_s@126.com user.name=sun_wk # 全局用戶簽名 user.email=sun_wk@126.com core.repositoryformatversion=0 core.filemode=false core.bare=false core.logallrefupdates=true core.symlinks=false core.ignorecase=true user.name=sha_hs # 本地用戶簽名 user.email=sha_hs@126.com
3、總結
- 在本地Git的安裝目錄下,
etc\gitconfig
文件:是對登陸該操作系統的所有用戶都普遍適用的配置。若使用git config
命令時加上--system
選項,讀寫的就是這個文件中的內容。 - 當前操作系統用戶目錄下
.gitconfig
文件:該配置文件只適用于該用戶,該用戶可以配置Git用戶簽名等信息到這個配置文件中,是對這臺計算機上所有的Git倉庫適用。若使用git config
命令時加上--global
選項,讀寫的就是這個文件中的內容。 - Git本地倉庫中
.git/config
文件:當前項目的Git本地倉庫中的配置文件,文件中的配置僅僅針對當前項目倉庫有效。
提示:每一個級別的配置都會覆蓋上層的相同配置。(local
覆蓋global
覆蓋system
)
原文鏈接:https://www.cnblogs.com/liuyuelinfighting/p/16164312.html
相關推薦
- 2022-05-18 python?安全地刪除列表元素的方法_python
- 2022-07-28 Redis基本數據類型String常用操作命令_Redis
- 2022-09-05 內置指令、自定義指令(詳細)、全局指令與局部指令
- 2023-07-28 獲取當前日期以及前6天的日期集合
- 2022-05-12 python遍歷文件夾內文件并檢索文件中的中文內容
- 2022-09-20 關于go-zero單體服務使用泛型簡化注冊Handler路由的問題_Golang
- 2022-03-24 Unity腳本自動添加頭部注釋的全過程_C#教程
- 2022-09-23 WPF仿微信實現截圖功能的方法詳解_C#教程
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支