Git配置用户签名方式的拓展示例实现全面讲解
作者:繁华似锦Fighting 发布时间:2023-03-12 14:46:59
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


猜你喜欢
- 1. 引言在Python相关代码中,我们经常会遇到如下代码段:# stuffif __name__ == "__main__&qu
- 本文实例为大家分享了python实现飞机大战的具体代码,供大家参考,具体内容如下实现的效果如下: 主程序代码如下:import p
- 本文主要给大家介绍的是关于python爬取散文网文章的相关内容,分享出来供大家参考学习,下面一起来看看详细的介绍:效果图如下:配置pytho
- 1. 原地排序:采用sort()方法,按照指定的顺序排列数据后用排序后的数据替换原来的数据(原来的顺序丢失),如:>>>
- DSDS应用场景1、背景“双卡手机”在中国手机市场占据近90%市场份额,随着软卡、云卡、eSIM的发展,双卡的应用也将更加广泛。此外,5G面
- 在这之前,你首先得了解Python中的PIL库。PIL是Python Imaging Library的简称,PIL是一个Python处理图片
- 目录背景法1,不适用法2,已不能用法3:Appnium法4:模拟操作整体代码后续工作及扩展总结背景由于课题需要爬取朋友圈的内容作为研究数据,
- 1. 实例描述在平时编程的过程中,会经常在网上翻译一些单词,本文使用Python制作一款翻译小工具,不仅可以自己用,还可以嵌入到程序当中。运
- 在使用mysql时,有时需要查询出某个字段不重复的记录,虽然mysql提供有distinct这个关键字来过滤掉多余的重复记录只保留一条,但往
- 序列化是将对象的状态信息转换为可以存储或传输的形式的过程。在序列化期间,对象将其当前状态(存在内存中)写入到临时或持久性存储区(硬盘)。以后
- python time.sleep()-睡眠线程还是进程?它会阻止线程。如果查看Python源代码中的Modules / timemodul
- 本文实例总结了MySQL数据库优化技术的索引用法。分享给大家供大家参考,具体如下:这里紧接上一篇《MySQL数据库优化技术之配置技巧总结》,
- 在这篇文章(不敢妄称教程,最多称之为学习笔记)里,我会从头开始实现客户端模板的效果。不过你不要期望能够在这里找到可以直接拿去使用直接复用灵活
- 简述队列一直都是工程化开发中经常使用的数据类型,本篇文章主要介绍一下python queue的使用,会边调试代码,边说明方法内容。环境pyt
- Mysql-connector-java驱动版本问题由于我的数据库版本是5.7.28 ,在使用java连接mysql时经常出现版本问题。co
- 本文实例总结了PHP常用字符串函数用法。分享给大家供大家参考,具体如下:字符串函数explore使用一个字符串分割另一个字符串结果为数组&l
- 有几个巨头公司,即Facebook和Netflix,决定禁止用户在控制台(console)执行JavaScript命令。 最初这是 由Fac
- function getTableDataByXML(inTable, inWindow) { var
- Python heapqheapq 库是 Python 标准库之一,提供了构建小顶堆的方法和一些对小顶堆的基本操作方法(如入堆,出堆等),可
- SQL Server数据库日志清除的两个方法:方法一一般情况下,SQL数据库的收缩并不能很大程度上减小数据库大小,其主要作用是收缩日志大小,