Git 进阶指南
Search…
前言
概念
Git SSH Keys 配置
Git Alias Cheat Sheet
origin 与 upstream
Git Stash 与 gwip
Git Tag 与 Describe
Subtree 与 Submodule
Cherry Pick 的使用场景
常见问题
如何配置多个提交用户?
如何撤销修改?
遇到冲突了怎么解决?
如何配置 git merge tool?
fetch pull merge rebase 的关系
分支操作流示例
其他问题汇总
Powered By
GitBook
如何配置多个提交用户?
1、git config user
假如你在 Github 上有个人项目,而公司项目存放在公司内网 gitlab 上,如何为这两种不同类型的项目配置不一样的提交用户呢?
Git 全局的用户配置文件存放在
~/.gitconfig
中,我们可以通过以下命令设置全局默认的用户名和邮箱。
git config --global user.name "<Your Name>"
git config --global user.email "<Your Email>"
如果需要为某一个项目配置不同的用户,则可以进入到项目对应的目录下,使用以下命令。它会在项目根目录的
.git/config
文件中保存这些配置信息:
git config user.name "<Another Name>"
git config user.email "<Another Email>"
2、Conditional Includes
在 git 2.13 版本中,增加了
conditional includes
配置,可以创建多个 gitconfig 文件,并针对不同的根目录使用不同的配置文件。例如,以下全局配置文件
~/.gitconfig
中包含以下用户配置信息,当项目 clone 在
~/dev/
目录下时,会自动使用另外一份配置文件:
[user]
name = Your Name
email =
[email protected]
[includeIf "gitdir:~/dev/"]
path = .gitconfig-dev
以下是
~/.gitconfig-dev
文件的配置:
[user]
name = Another Name
email =
[email protected]
注意:强烈建议将 global user 配置为你的 Github ID,避免默认提交中有效用户信息的缺失,导致 Github contributions 不准确。同时,不设置为公司邮箱,可以避免邮箱信息泄露。
概念 - Previous
Cherry Pick 的使用场景
Next - 常见问题
如何撤销修改?
Last modified
3yr ago
Copy link
Outline
1、git config user
2、Conditional Includes