git
  • 安装教程
  • 本地仓库
    • 工作区与版本库
    • 版本管理
      • 创建版本库
      • 提交修改
      • 撤消修改
      • 删除文件
    • 分支管理
      • 创建分支
      • 合并分支
      • 删除分支
    • 标签管理
      • 创建标签
      • 删除标签
  • 远程仓库
    • 初始化远程库
    • 克隆远程库
    • 多人协作
    • 远程分支
    • 远程标签
    • 关于origin
    • 关于upstream
  • 关于config
    • 关于name与email
    • window上的凭证
  • git常用命令
  • github的使用
  • 容器跑gogs
  • 项目版本管理
    • GitFlow
Powered by GitBook
On this page
  • 设置用户名与邮箱
  • 查看用户名与邮箱
  • Reference

Was this helpful?

  1. 关于config

关于name与email

Previous关于configNextwindow上的凭证

Last updated 5 years ago

Was this helpful?

我们一般在主机上装好git后,都需要通过以下的两条命令设置user.name与user.email信息

$ git config --global user.name xxxx
$ git config --global user.email xxxx@example.com

当我们有多台主机向git服务器提交代码时, 此时git服务器就需要知道每一次提交是谁的。此时,就是通过user.name来进行区分。

比如,我们从两台不同的主机上向gogs中的learngit项目进行两次提交,在该项目中就可以看到两次提交的user.name是不一样的(注意,尽管两次提交用的都是gogs中的pshizh同一个用户)

上图中的docker162就是162主机上的user.name,docker163就是163主机上的user.name

但是但是,在github上,commit history中显示的不是主机上设置的user.name,而是github的账号(当我们git push到github时,是携带了github账号的信息的):

设置用户名与邮箱

$ git config --[local|global|system] user.name xxx
$ git config --[local|global|system] user.email xxx@example.com

在设置用户名与邮箱的时候,可以设置不同的范围:

  • local:当前仓库,在当前仓库的.git/config文件中

  • global:当前用户,在当前用户的~/.gitconfig文件中

  • system:系统范围,在/etc/gitconfig文件中

最佳实践:有可能同一台主机需要连接多个远程仓库,而且每个远程仓库的用户名可能不一样,所以最好使用--local选项给每个项目单独设置,设置为远程仓库的登录用户名。

查看用户名与邮箱

$ git config user.name
$ git config user.email

上面的命令查找的范围依次是local、global、system。

Reference

[1]

[2]

https://blog.csdn.net/hutaoer06051/article/details/8275069
https://www.jianshu.com/p/d24e791a7679