git使用过程中有些设置是必不可少的,比如作者信息pull的rebase策略等等,记录一下常用的设置
1. 基本设置
1.1. 用户和邮箱
1
2
|
git config --global user.name "coco"
git config --global user.email "cocoding.vincent@gmail.com
|
1.2. 设置代理
1
|
git config --global http.proxy socks5://127.0.0.1:1080
|
1.3. 自动处理换行符
1
|
git config --global core.autocrlf true
|
自动处理换行符其实不好,比如dockerfile经常因为这个问题搞的起不来,也找不到原因,最好统一为
1
2
|
git config --global core.autocrlf false
git config --global core.eol lf
|
1.4. 设置是否启用filemode
1
|
git config --global core.filemode false
|
1.5. pull是否启用rebase
1
|
git config --global pull.rebase true
|
1.6. 修改默认的编辑器
1
|
git config –global core.editor vim
|
1.7. 设置git为英文
1
|
echo "alias git='LANG=en_US.UTF-8 git'" >> ~/.zshrc
|
1.8. commit模板
1
2
3
4
|
# windows 最好写绝对路径, 之前试过c盘大小写会造成不识别路径
git config --global commit.template c:\Users\oherg\.git-commit-template.txt
# linux and macOS
git config --global commit.template ~/.git_commit_template.txt
|
这里贴一个标准模板
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# Please write your commit messages according to the following specifications
# <type>[optional scope]: <description>
# break line
# [optional body]
# break line
# [optional footer(s)]
# ======================================
# Type should be one of the following:
# ======================================
# * build 构建相关代码和文件
# * chore 构建过程或者辅助工具的变动
# * ci CI or CD
# * docs 文档相关变动
# * feat 新功能特性
# * fix 修复
# * perf 优化,性能提升
# * refactor 重构
# * revert 回滚
# * style 代码样式或者格式化代码
# * test 测试
# * merge 合并
# * sync 同步
# 如果是破坏性的改动,必须加上!,并且在footer加上BREAKING CHANGE:
# ======================================
# Scope:
# ======================================
# scope就是影响范围
# 比如: compile, build, *, view, service
# 根据业务和项目自己把握,能用来区分层次
# ======================================
# Description:
# ======================================
# 字数不要超过80
# 首字母小写
# 第一个是一个动词
# 不要句号
# ======================================
# Description:
# ======================================
# ======================================
# Examples
# ======================================
# feat(*): add library for tailwind
#
# install development libraries by npm install
# - postcss
# - postcss-cli
# - autoprefixer
# - @snowpack/plugin-postcss
#
# Refs #133
# Closes #123, #245, #992
|
1
2
3
4
5
6
|
# merge tool
git config --global merge.tool vimdiff
# 省略提示
git config --global mergetool.prompt false
# 不保留备份文件
git config --global mergetool.keepBackup false
|
2. 检查设置
查看原始设置
1
|
git config --list --show-origin.
|
查看我们的设置
3. alias
另外还有些有用的alias,可以简化我们的git命令
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# git push
git config --global alias.p 'push'
# git status
git config --global alias.st 'status -sb'
# git log
git config --global alias.ll 'log --oneline'
git config --global alias.lla 'log --oneline --decorate --graph --all'
# last commit
git config --global alias.last 'log -1 HEAD --stat'
# git commit
git config --global alias.cm 'commit'
git config --global alias.cmm 'commit -m'
# git checkout
git config --global alias.co 'checkout'
# git remote
git config --global alias.rv 'remote -v'
# git diff
git config --global alias.d 'diff'
git config --global alias.dv 'difftool -t vimdiff -y'
# list git global config
git config --global alias.gl 'config --global -l'
# git branch
git config --global alias.br "branch --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(contents:subject) %(color:green)(%(committerdate:relative)) [%(authorname)]' --sort=-committerdate"
# reset last
git config --global alias.undo 'reset HEAD~1 --mixed'
|
如果觉得这样还不方便,就直接在bashrc
, zshrc
里去设置alias
比如:
1
2
3
4
5
6
7
|
alias g='git'
alias ga='git add'
alias gaa='git add --all'
alias gapa='git add --patch'
alias gau='git add --update'
alias gap='git apply'
|
可以参考:
如果是用ohmyzsh,有git插件已经实现了, 无需手动设置