查看配置信息
要检查已有的配置信息,可以使用 git config --list
命令:
有时候会看到重复的变量名,那就说明它们来自不同的配置文件(比如 /etc/gitconfig
和 ~/.gitconfig
),不过最终 Git 实际采用的是最后一个。
也可以直接查阅某个环境变量的设定,只要把特定的名字跟在后面即可,像这样:
$ git config user.name
Scott Chacon
git在push/push to时需要使用到user.name和user.email,一般通过git bash来进行配置或修改。
配置user.name/user.email
//配置user.name
git config --global user.name "your user name"
//配置user.email
git config --global user.email "your user email"
查看user.name/user.email
$ git config user.name
ysqgit
$ git config user.email
13438893465@163.com
这里需要注意的是,该命令只能用于初次配置user.name/email,如果不小心配置错误,或者重复配置,不可以通过重复执行以上命令来修改user.name/email,否则可能或报错说无法重复配置,或者导致一个key配置了多个value
修改user.name/user.email
如果想要修改已经配置过的user.name或email,有两种方式,一种是通过git bash来修改;一种是直接修改.gitconfig文件。
1. git bash
//修改user.name
git config --global --replace-all user.name "your user name"
//修改user.email
git config --global --replace-all user.email"your user email"
2. 修改.gitconfig文件
- 该文件是隐藏文件,位于
C:\Users\{user}\.gitconfig
,直接修改里边的name或者email,如果有重复的name或email,可以将其删掉,只剩下一个就好。 - 修改完,通过git bash输入git config –list可以查看是否修改成功了。
3.下面是完整的例子
修改:
user.name=ysqgit
user.email=13438893465@163.com
为:
user.name=yangshuqiugithub
user.email=421072757@qq.com
操作命令为:
lollicup@DESKTOP-4M99Q31 MINGW64 /d/www/lollicupStore2 (sun_master_ios_api)
$ git config --global --replace-all user.name yangshuqiugithub
lollicup@DESKTOP-4M99Q31 MINGW64 /d/www/lollicupStore2 (sun_master_ios_api)
$ git config --global --replace-all user.email 421072757@qq.com
$ git config --list
core.symlinks=false
core.autocrlf=true
core.fscache=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
help.format=html
rebase.autosquash=true
http.sslbackend=openssl
http.sslcainfo=D:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
credential.helper=manager
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
user.name=ysqgit
user.email=13438893465@163.com
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true
remote.origin.url=https://github.com/lollicupusa/lollicupStore2.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
branch.storex.remote=origin
branch.storex.merge=refs/heads/storex
branch.aaron.remote=origin
branch.aaron.merge=refs/heads/aaron
branch.master-sun-no-pl-dev.remote=origin
branch.master-sun-no-pl-dev.merge=refs/heads/master-sun-no-pl-dev
branch.sort.remote=origin
branch.sort.merge=refs/heads/sort
branch.master-sun-no-pl-dev-solr-search.remote=origin
lollicup@DESKTOP-4M99Q31 MINGW64 /d/www/lollicupStore2 (sun_master_ios_api)
$ git config --global --replace-all user.name yangshuqiugithub
lollicup@DESKTOP-4M99Q31 MINGW64 /d/www/lollicupStore2 (sun_master_ios_api)
$ git config --global --replace-all user.email 421072757@qq.com
lollicup@DESKTOP-4M99Q31 MINGW64 /d/www/lollicupStore2 (sun_master_ios_api)
$ git config --list
core.symlinks=false
core.autocrlf=true
core.fscache=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
help.format=html
rebase.autosquash=true
http.sslbackend=openssl
http.sslcainfo=D:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
credential.helper=manager
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
user.name=yangshuqiugithub
user.email=421072757@qq.com
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true
remote.origin.url=https://github.com/lollicupusa/lollicupStore2.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
branch.storex.remote=origin
branch.storex.merge=refs/heads/storex
branch.aaron.remote=origin
branch.aaron.merge=refs/heads/aaron
branch.master-sun-no-pl-dev.remote=origin
branch.master-sun-no-pl-dev.merge=refs/heads/master-sun-no-pl-dev
branch.sort.remote=origin
branch.sort.merge=refs/heads/sort
branch.master-sun-no-pl-dev-solr-search.remote=origin
: