Git 别名配置

一、 文件位置

Linux 系统

全局配置

~/.gitconfig

当前项目下

.git/.gitconfig(覆盖用户级)

二、配置简介

 这里有一些例子你可以试试:

$ git config --global alias.co checkout
$ git config --global alias.br branch
$ git config --global alias.ci commit
$ git config --global alias.st status

这意味着,当要输入 git commit 时,只需要输入 git ci。 随着你继续不断地使用 Git,可能也会经常使用其他命令,所以创建别名时不要犹豫。

在创建你认为应该存在的命令时这个技术会很有用。 例如,为了解决取消暂存文件的易用性问题,可以向 Git 中添加你自己的取消暂存别名:

$ git config --global alias.unstage 'reset HEAD --'

这会使下面的两个命令等价:

$ git unstage fileA
$ git reset HEAD -- fileA

三、系统配置

全局

$ git config --global user.name  cpz
$ git config --global user.email cpz@test.com

局部(当前项目)

$ git config user.name  cpz
$ git config user.email cpz@test.com

快速打开gitconfig

git config [--global] --edit

修改编辑器

$ git config --global core.editor emacs

查看gitconfig内容

$ git config --list

git alias配置

[alias]
st = status -sb
co = checkout
br = branch
mg = merge
ci = commit
ds = diff --staged
dt = difftool
mt = mergetool
last = log -1 HEAD
latest = for-each-ref --sort=-committerdate --format=\"%(committername)@%(refname:short) [%(committerdate:short)] %(contents)\"
ls = log --pretty=format:\"%C(yellow)%h %C(blue)%ad %C(red)%d %C(reset)%s %C(green)[%cn]\" --decorate --date=short
hist = log --pretty=format:\"%C(yellow)%h %C(red)%d %C(reset)%s %C(green)[%an] %C(blue)%ad\" --topo-order --graph --date=short
type = cat-file -t
dump = cat-file -p
lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
[core]
autocrlf = true
[push]
default = simple
[color]
ui = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "status"]
added = yellow
changed = green
untracked = cyan
[color "diff"]
meta = yellow
frag = magenta bold
commit = yellow bold
old = red bold
new = green bold
whitespace = red reverse
[color "diff-highlight"]
oldNormal = red bold

  

 

可以参考:

https://github.com/SixArm/sixarm_git_gitconfig

https://github.com/GitAlias/gitalias

 

posted @ 2020-01-08 13:30  踏雪无痕SS  阅读(1017)  评论(0编辑  收藏  举报