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
猜你喜欢
- 首先需要安装arrow库:pip install arrowArrow提供了一个合理的、人性化的方法来创建、操作、格式转换的日期,时间,和时
- 在这之前我们先回顾以前用php导出excel,我直接写成方法在这里:public static function phpExcelList(
- 第一步:下载和安装python-3.4.4amd.msi可以去官方网站下载,也可以从网盘下载: 链接: https://pan.baidu.
- 这篇文章主要介绍了Python argparse模块使用方法解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值
- 内容摘要:本文介绍了asp使用正则表达式自动解析远程图片地址并下载保存的方法,值得收藏!一、使用正则表达式Regexp匹配取得原页中的图片的
- 假如你目前需要在Microsoft Access数据库中指示不存在数据,可以在“文本”或&l
- 饼图常用于统计学模块,画饼图用到的方法为:pie( )一、pie()函数用来绘制饼图pie(x, explode=None, labels=
- 页面跳转页面跳转的url中必须在最后会自动添加【\】,所以在urls.py的路由表中需要对应添加【\】from django.shortcu
- 当你要使用data URI scheme的时候,你会发现,虽然他可以使用在绝大多数浏览器上,但无法再IE6和IE7上工作。不过值得庆幸的这一
- 本文实例讲述了Python实现嵌套列表及字典并按某一元素去重复功能。分享给大家供大家参考,具体如下:#! /usr/bin/env pyth
- 1、最优化与线性规划最优化问题的三要素是决策变量、目标函数和约束条件。线性规划(Linear programming),是研究线性约束条件下
- 如下所示:from kafka import KafkaClientfrom kafka.producer import SimplePro
- 递归函数及递归次数受到限制一个函数在内部调用自己,那么这个函数是递归函数。递归会反复使用本身,每递归一次,越接近最终的值。当一个问题可以由许
- 1.如果客户端和服务器端的连接需要跨越并通过不可信任的网络,那么就需要使用SSH隧道来加密该连接的通信。2.用set password语句来
- 一、字符串离散化示例对于一组电影数据,我们希望统计电影分类情况,应该如何处理数据?(每一个电影都有很多个分类)思路:首先构造一个全为0的数组
- 记得以前的windows 任务定时是可以的正常使用的,今天试了下,发现不能正常使用了,任务计划总是挂起。接下来记录下python 爬虫定时任
- 代码如下:CREATE TABLE #tmptb(tbname sysname,tbrows int ,tbREserved varchar
- 本文实例讲述了python通过索引遍历列表的方法。分享给大家供大家参考。具体如下:python中我们可以通过for循环来遍历列表:colou
- 假设mysql安装在c:盘,mysql数据库的用户名是root,密码是123456,数据库名是database_name,在d:盘根目录下面
- 这篇文章主要介绍了python线程join方法原理解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋