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
相关推荐
Doris_LMS1 天前
Git的强软硬回退(三)
运维·服务器·数据库·git·idea
瓜酷月..1 天前
GIT(了解)
git
misty youth1 天前
git命令常用指南
git·github
持续迷茫1 天前
lint-staged 中 --verbose 选项的深度解析
前端·git
lostElk1 天前
团队 Git 分管理全流程规范
git·github
亦是行人!1 天前
删除git中已经提交的target、logs、.idea文件
git
匆叔1 天前
Git下载全攻略
前端·git
奇树谦2 天前
Git配置:禁用全局HTTPS验证
git·网络协议·https
小安同学iter2 天前
在idea当中git的基础使用
git
初级代码游戏2 天前
Git或TortoiseGit的小BUG(可解决):空库报错Could not get hash of ““
git·bug