查看配置 git config
参考原文链接:https://my.oschina.net/u/3683692/blog/3026984
- 查看所有的设置
git config list
或者
git config -l
- 查看选项配置 git config -l ,选项参数
- –system: 系统配置(所有git账户)
- –global: 全局配置(一个用户)
- –local: 项目[本地]配置(一个项目), 或者叫仓库配置
只能在项目目录下,使用 --local ,读取的是 .git/config
优先级:由高到低
git config > git config --global > git config --system
如:查看全局配置选项命令:
git config -l --global 或 git config --global -l
git config -l 或者 git config -l --local
git config -l --system
不带参数-l, 默认是项目的配置(–local);参数顺序可先可后
修改配置
- 和上面查看一样,只不过参数由 -l(list) 变成 -e (edit)
git config -e --global
git config -e --system
git config -e --local 或者 git config -e
不带参数-l, 默认是项目的配置(–local);参数顺序可先可后
配置文件的位置
system: 在git 工具的安装目录下
如:F:\devTools\Git\etc\gitconfig
global: 在系统盘,宿主目录下. ~/.gitconfig
如:C:\Users\laozhongyi.gitconfig
local: 在项目下的目录中, ./git/config
如:/项目目录/.git/config
设置信息
- 方法1: 使用上面的修改命令,git config -e
- 方法2: 单独设置 如:设置用户信息
git config --global user.name 'xxxx'
git config --global user.email 'xxxx@qq.com'
其他:
//设置编辑器,默认是 vi vim
git config --global core.editor sublime
//显示颜色
git config --global color.ui true
//设置比较工具
git config --global merge.tool vimdiff
注:Git可以接受kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff,
ecmerge, 和 opendiff作为有效的合并工具。你也可以设置一个客户化的工具
单独查看某一项的配置
git config user.name
git alias [ˈeɪliəs] 的使用
设置方法
- 设置方法1. git config --global alias.快捷名 命令名
git config --global alias.s status
使用:git s
- 设置方法2. 直接在配置文件 ~/.gitconfig 中添加,修改
使用git alias
首先要修改配置文件
linux系统 ↓↓↓
第一步 用你最喜欢的编辑器打开 ~/.gitconfig
第二步 再配置文件中加入alias块,内容如下,根据你的偏好进行修改
[alias]
co = checkout
ss = status
cm = commit -m
br = branch
bm = branch -m
bd = branch -D
cb = checkout -b
df = diff
ls = log --stat
lp = log -p
plo = pull origin
plode = pull origin develop
pho = push origin
windows系统 ↓↓↓
windows系统的配置文件一般是位于git安装目录下的etc\gitconfig文件。
co = checkout // 切换分支,或去到特定的commit
ss = status
cm = commit -m
br = branch
bm = branch -m // 修改当前分支的名称
bd = branch -D // 删除某个分支
cb = checkout -b // 新建一个和当前分支一样的分支,并切换过去
df = diff
ls = log --stat // 查看每次提交修改了哪些文件, git ls -n, 只看最近的n次提交
lp = log -p // 查看每次提交修改了那些行,git lp -n, 只看最近n次提交
plo = pull origin
pho = push origin
- 设置方法3.如果我们想要命令更简单,如 git s -> gits, 就可以linux系统中添加alias了,在文件~/.bashrc 中
alias gs='git status'
alias gc='git commit -m '
alias gaa= 'git add .'
alias gp='git push'
alias gl='git log --graph'
命令添加后,让修改的文件立即生效,使用命令 source ~/.bashrc 或者 . ~/.bashrc
应用:美化git log
- 在配置文件 \Git\etc\bash.bashrc 中添加以下命令即可
alias gl="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
删除方法
git config --global --unset alias.别名
补充git缩写配置/配置别名
我们只需要敲一行命令,告诉Git,以后st就表示status:
git config --global alias.st status
现在可以敲 git st看看效果。
当然还有别的命令可以简写,很多人都用co表示checkout,ci表示commit,br表示branch:
git config --global alias.co checkout
git config --global alias.ci commit
git config --global alias.br branch