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
相关推荐
大柏怎么被偷了10 小时前
【Git】远程操作
git
studytosky10 小时前
Linux 基础开发工具(3):Git 控制与 GDB 调试实用指南
linux·运维·服务器·网络·数据库·git
云闲不收12 小时前
AI编程系列——git-worktree并行开发
git·ai编程
秦时明月天明12 小时前
GitLab SSH Key 过期:git pull failed : remote your ssh key has expired
git·ssh·gitlab
桃花岛主7013 小时前
命令提交git到github上的步骤
git·github
AI逐月13 小时前
Git 停止追踪已提交文件问题
大数据·git·elasticsearch
是毛毛吧13 小时前
开发环境配置指南:解决 GitHub 连接超时与依赖下载失败的问题
网络·git·网络安全·docker·信息与通信
bj_zhb14 小时前
git stash 用法
git
rockmelodies14 小时前
本地 PyCharm 生成的 Git 仓库与 GitHub 远程仓库关联起来
git·pycharm·github
阿萨德528号14 小时前
Git 与 SVN 对比详解
git·svn