Git 在不同的项目使用不同的author

安装好 Git 的时候,每个人都会设置全局的账户:

git config --global user.name "laixintao"
git config --global user.email "laixintao1995@163.com"

公司的 Git 账户和个人的 Git 账户不一样,可以在项目中设置此项目的 Author :

git config user.name "laixintao"
git config user.email "laixintao1995@163.com"

这样私人账户每次都要设置,可以设置一条 Git 的 alias ,这样每次都用这一条命令就可以了。

git config --global alias.private 'config user.email "laixintao1995@163.com"'

其实 git config –global 命令是修改的一个文件,$HOME/.gitconfig 例如我的文件如下:

[core]
        editer = "/usr/local/bin/vim"
        editor = vim
        excludesfile = ~/.gitignore_global
[user]
        name = laixintao
        email = laixintao1995@163.com
        username = laixintao
[alias]
        pr = pullrequest
        ck = checkout
        br = branch
        lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
[merge]
        tool = vimdiff
        conflictstyle = diff3
[pull]
    rebase = true
[mergetool]
        prompt = false
[github]
        user = laixintao1995@163.com
[filter "lfs"]
        process = git-lfs filter-process
        required = true
        clean = git-lfs clean -- %f
        smudge = git-lfs smudge -- %f

同之前提到的 myrc 项目一样,gitconfig 这个文件我也是用 git 来追踪的,去一个新环境只要安装好这个项目就可以回到自己熟悉的 git 了。

发布于:2019-10-25 01:19:59