git配置1-不同的项目使用不同用户名或邮箱

  • [1. 全局用户名和邮箱](#1. 全局用户名和邮箱)
    • [1.1. 设置](#1.1. 设置)
    • [1.2. 存储](#1.2. 存储)
    • [1.3. 查看](#1.3. 查看)
  • [2. 针对指定项目单独设置](#2. 针对指定项目单独设置)
    • [2.1. 设置](#2.1. 设置)
    • [2.2. 存储](#2.2. 存储)
    • [2.3. 查看](#2.3. 查看)

1. 全局用户名和邮箱

1.1. 设置

bash 复制代码
git config --global user.name '张三'
git config --global user.email 'zhangsan@example.com'

1.2. 存储

git的全局配置一般会存在home目录的 .gitconfig文件。如 /Users/spencer/.gitconfig

可以通过以下命令查看全局配置的内容:

bash 复制代码
cat ~/.gitconfig

这个配置是全局生效的,即你所有的仓库都会默认使用这个配置(有针对指定的仓库单独配置的除外)。

1.3. 查看

bash 复制代码
git config --global user.name
git config --global user.email

# 查看所有的配置
git config --global --list

2. 针对指定项目单独设置

2.1. 设置

bash 复制代码
# 进入自己项目的根目录
cd [your_project_dir]

# 设置用户名和邮箱
git config user.name '张三'
git config user.email 'zhangsan@example.com'

2.2. 存储

针对指定项目的配置会存在项目目录的 .git/config文件。如 /Users/spencer/workspace/common_util/.git/config

这个配置只针对你当前的项目有效,且优先级高于全局配置(如全局配置的user.name是张三,项目配置的user.name是李四,那么实际上你在这个项目中提交的commit的用户名是李四)。

2.3. 查看

bash 复制代码
git config user.name
git config user.email
相关推荐
2501_903238657 分钟前
Git Bash:Windows下的强大命令行工具
windows·git·bash·个人开发
神明木佑2 小时前
datalist 是什么?以及作用是什么?
git
那片海还在吗4 小时前
使用 Git、Postman、Newman、Jenkins 与邮件构建自动化接口测试及通知流程
git·jenkins·postman
heeheeai11 小时前
git 国内源
git
the_seventh_dog12 小时前
git | 团队协作开发注意事项
git
yinshuilan15 小时前
今日运维之-Mac笔记本python环境问题
运维·git·python·brew
辄也16 小时前
git拉取远程分支到本地分支
git
皮克斯的进化之路16 小时前
Git原理+使用(超详细)
git
wrjwww16 小时前
【Git学习笔记】Git常用命令
笔记·git·学习
大乔乔布斯17 小时前
WSL,Power shell 和CMD, Git bash的区别
开发语言·git·bash