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
相关推荐
百锦再12 小时前
第10章 错误处理
java·git·ai·rust·go·错误·pathon
静心观复1 天前
git revert 2
git
枫子有风1 天前
Git 简介和基础使用
git
FrankYoou1 天前
git stash push 命令作用及使用场景
git
眼小博2 天前
多人协作Git开发流程指南
git
lpfasd1232 天前
git-团队协作基础
chrome·git·elasticsearch
John Song2 天前
git多个账号管理
git·github
CV_J2 天前
解决Git 冲突后本地提交丢失/未推送问题
git
__Witheart__2 天前
Git 某个分支恢复到某个特定的 commit 状态
git
XU磊2602 天前
Git 实现github仓库管理-删除指定目录下的所有文件并保留目录结构
git·github