工作中需要经常使用git命令,使用一些简写命令还是能提高一丢丢效率的。
mac上放在 ~/.zshrc 下就行,添加完后执行source ~/.zshrc,linux中创建 ~/.bash_aliases,在/etc/profile添加 [[ -f ~/.bash_aliases ]] && source ~/.bash_aliases 内容
首先在 ~/.gitconfig 中加入如下配置:
[alias] st = status # Checkout a branch co = checkout # Checkout a new not yet existing branch ci = commit # Commit you changes ft = fetch -p # Fetch from a repository pu = push # Push you changes to repository ba = branch -a # List both remote-tracking branches and local branches bd = branch -d # Delete a branch only if it has been merged dc = diff --cached # Display the staged changes lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit # Display Submit log rk = shortlog -sn --no-merges # Display Contributor ranking [user] name = anzhihe email = you@email.com
在 ~/.zshrc 中添加如下配置:
alias git='LANG=en_GB git' # Mac git中文提示改为英文 alias gin='git init' # 初始化仓库 alias gst='git st' # 查看状态 alias gdf='git diff' # 查看修改内容 alias gad='git add *' # 添加到暂存区 gci(){ git ci -am "$*"; } # 提交到本地仓库 alias glg='git lg' # 查看提交历史 alias grg='git reflog' # 查看操作历史 alias gco='git checkout -- ' # 放弃修改,添加至暂存区 alias grh='git reset HEAD^' # 回退到上一版本 #alias gra ='git remote add' # 添加远程地址 alias gpl='git pull' # 更新仓库 alias gba='git branch -a' # 查看分支 alias gbb='git branch -b' # 创建并切换到分支 alias gps='git push' # 提交远程仓库 alias gpur='git pull upstream master --rebase' # 更新关联的上游项目 # 批量更新多个仓库 alias gpa="find . -maxdepth 3 -name .git -type d | rev | cut -c 6- | rev | xargs -I {} git -C {} pull"
参考: