当前位置:   article > 正文

Git配置用户名和邮箱_gitname和email

gitname和email

设备:Windows10,git(MINGW64)


一般刚安装Git都要配置用户名和邮箱,因为你提交代码到本地仓库(上传代码到远程仓库)时会用到,如果没有没有配置,在你提交时它会提醒你的。

那么接下来我们讲一下怎么配置:


目录

1、查看git的配置列表

2、进行配置

(1)命令行配置

补充:(1.1) 全局变量

    (1.2)局部变量

注意:局部变量覆盖全局变量!!!和编程语言里面的变量关系是一样的。

(2)修改对应文件进行配置

3、修改已配置的信息

(1)用命令修改

(2)修改对应文件进行修改

4、git config命令的功能列表

(1)git config

(2)git config --help


1、查看git的配置列表

我们可以先查看一下git的配置列表:

git config --list

如果没有配置东西,应该是空的。照着下面配置完成后,你可以再试一下该命令,就会出现一系列配置信息。

 

2、进行配置

(1)命令行配置

git config --global user.name  "username"  
git config --global user.email  "email"

将username和email换成github(或者其它类似远程仓库)的用户名和邮箱。

补充:(1.1) 全局变量

 --global  表示全局的,即当前用户都有效,该配置会出现在 ~/.gitconfig 文件中,~表示当前用户的目录,比如我的是:C:\Users\username\.gitconfig ,打开该文件你会发现如下图所示的内容:

对比一下,你应该就知道上面的配置命令是怎么起作用的吧(其它配置命令也是这个意思!)。(注:该文件#开头的行是注释,为了方便理解,你可以自己添加一些注释信息)

    (1.2)局部变量

既然有全局的,那么肯定有局部的啊!局部的是不加 --global 的,如下:

git config  user.name  "username"  
git config  user.email  "email"

局部是只对当前仓库起效的,它的配置信息会在当前仓库根目录/.git/config文件下:

 

注意:局部变量覆盖全局变量!!!和编程语言里面的变量关系是一样的。

我在上面我新建的那个仓库里,随便提交了一点东西,然后查看提交日志如下:

 

(2)修改对应文件进行配置

相信看了上面的补充内容之后,你应该已经了解这两个配置命令的作用了吧,所以这里就不详讲了,你找到对应文件,该相关设置就好了。

 

3、修改已配置的信息

假如配置后,发现有信息配置错了,如何进行修改?

(1)用命令修改

这里演示修改本地仓库的用户名和邮箱:

git config --replace-all user.name "name"

git config --replace-all user.email "123@qq.com"

修改后是这样的:

 

(2)修改对应文件进行修改

这个应该不用讲了。

 

4、git config命令的功能列表

(1)git config

我们直接输入git config,就可以看到简单的命令列表了:

  1. $ git config
  2. usage: git config [<options>]
  3. Config file location
  4. --global use global config file
  5. --system use system config file
  6. --local use repository config file
  7. --worktree use per-worktree config file
  8. -f, --file <file> use given config file
  9. --blob <blob-id> read config from given blob object
  10. Action
  11. --get get value: name [value-regex]
  12. --get-all get all values: key [value-regex]
  13. --get-regexp get values for regexp: name-regex [value-regex]
  14. --get-urlmatch get value specific for the URL: section[.var] URL
  15. --replace-all replace all matching variables: name value [value_regex]
  16. --add add a new variable: name value
  17. --unset remove a variable: name [value-regex]
  18. --unset-all remove all matches: name [value-regex]
  19. --rename-section rename section: old-name new-name
  20. --remove-section remove a section: name
  21. -l, --list list all
  22. -e, --edit open an editor
  23. --get-color find the color configured: slot [default]
  24. --get-colorbool find the color setting: slot [stdout-is-tty]
  25. Type
  26. -t, --type <> value is given this type
  27. --bool value is "true" or "false"
  28. --int value is decimal number
  29. --bool-or-int value is --bool or --int
  30. --path value is a path (file or directory name)
  31. --expiry-date value is an expiry date
  32. Other
  33. -z, --null terminate values with NUL byte
  34. --name-only show variable names only
  35. --includes respect include directives on lookup
  36. --show-origin show origin of config (file, standard input, blob, command line)
  37. --default <value> with --get, use default value when missing entry

(2)git config --help

这个命令默认打开本地git安装目录下的G:\Git\mingw64\share\doc\git-doc\下的详细的说明文档(这里G:\Git为安装目录),这个是详细介绍命令的作用(上面的那个只是简介)。

样例截图:

延伸:其它命令你也可以通过添加  --help 参数来打开命令的相关文档说明,如 git diff --help,……


2021年3月18日14:53:50 更新

之前文章名为“Git配置用户名和密码”,这个有问题的,因为git其实并没有密码,有密码的是git远程仓库,比如github,因此在此进行更正。

end.

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号