Git 配置
- 简介
命令行查看配置
- 查看帮助
git config --help
- 查看全局配置
git config --global --list
- 查看系统配置
git config --system --list
- 查看当前配置
git config --local --list
权重 ------ 仓库>全局>系统
全局配置
安装 Git
后 ,首先要配置的是全局的用户名和邮箱📮
命令行配置如下:
git config --global user.name "username"
git config --global user.email demo@example.com
Mac 电脑的 全局配置文件路径 ~/.gitconfig
- 直接编辑文本
vi ~/.gitconfig
配置 diff - merge
工具 Kaleidoscope
[diff]
tool = Kaleidoscope
[difftool]
prompt = false
[difftool "Kaleidoscope"]
cmd = ksdiff --partial-changeset --relative-path \"$MERGED\" -- \"$LOCAL\" \"$REMOTE\"
[merge]
tool = Kaleidoscope
[mergetool]
prompt = false
[mergetool "Kaleidoscope"]
cmd = ksdiff --merge --output \"$MERGED\" --base \"$BASE\" -- \"$LOCAL\" \"$REMOTE\"
[diff "exif"]
textconv = exiftool
[diff "plist"]
textconv = plutil -convert xml1 -o -
配置别名
[alias]
br = branch
ca = commit -a
ci = commit
co = checkout
st = status
oln = log --pretty=oneline --since='2 days ago' --color --graph --abbrev-commit
olg = log -p -1 --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%ci) %C(bold blue) <%an>%Creset' --abbrev-commit
lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%ci) %C(bold blue) <%an>%Creset' --abbrev-commit
amend = !git log -n 1 --pretty=tformat:%s%n%n%b | git commit -F - --amend
zip = !git archive --format zip master --output
zipHead = !git archive --format=zip HEAD --output
rmd = !git ls-files -d -z | xargs -0 git rm
配置颜色
[color]
diff = auto
status = auto
branch = auto
interactive = auto
- 账户信息
[user]
name = manajay
email = manajay@company.com
[github]
user = manajay
token = 942cmanajay1f1c46dmanajay618manajay7e1
- 其他配置
[log]
date = local
[core]
excludesfile = ~/.gitignore_global # 无需纳入 Git 管理的文件
whitespace = cr-at-eol # 让 Git 知道行尾回车符是合法的
quotepath = false
editor = /usr/local/bin/nvim # 默认编辑器
attributesfile = ~/.gitattributes
[i18n]
commitencoding = utf-8
logoutputencoding = utf-8
[gui]
encoding = utf-8
[push]
default = current
[grep]
lineNumber = true
[help]
format = html
- 全局忽略文件的配置
~/.gitignore_global
_Store
.DS_Store?
*.<Plug>(StopHL)<Plug>(StopHL)swp
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
项目配置
类似全局配置文件, 路径在项目的 .git/config
里面, 要特别注意的是配置的权重也就是优先级问题
- 查看当前配置
git config --local --list
demo
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[submodule]
active = .
[remote "origin"]
url = https://xxxxx.git
fetch = +refs/heads/*:refs/remotes/origin/*
sslVerify = true
gtServiceAccountIdentifier = xxxxx
[difftool "tower"]
cmd = \"/Applications/Tower.app/Contents/Resources/kaleidoscope.sh\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"
[mergetool "tower"]
cmd = \"/Applications/Tower.app/Contents/Resources/kaleidoscope.sh\" \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\"
trustExitCode = true
[branch "master"]
remote = origin
merge = refs/heads/master
- 推荐使用
Tower
应用