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 '[email protected]'

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 '[email protected]'

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
相关推荐
司徒小夜6 小时前
处理git没做修改,但是文件显示变更的情况
git
m0_749317527 小时前
vscode里如何用git
ide·git·vscode
Hello.Reader8 小时前
Git 安装全攻略Linux、macOS、Windows 与源码编译
linux·git·macos
王景程9 小时前
SELinux是什么以及如何编写SELinux策略
git·github
Chuncheng's blog9 小时前
如何基于Mihomo Party http端口配置git与bash命令行代理
git·http·bash
Tom Boom9 小时前
Git常用命令完全指南:从入门到精通
大数据·git·elasticsearch·docker·自动化测试框架
不爱学英文的码字机器11 小时前
[Git] 文件删除
git
DZSpace12 小时前
git stash命令用法
git
Vowwwwwww12 小时前
GIT历史存在大文件的解决办法
前端·git·后端
@BreCaspian13 小时前
Git 推送失败解决教程——error: failed to push some refs to
大数据·git·elasticsearch