美文网首页
工作中好用的git alias别名

工作中好用的git alias别名

作者: 陈卧虫 | 来源:发表于2019-05-12 20:06 被阅读0次

工作中好用的git alias别名

对于经常使用git命令的,有时候必须输入一些较长的命令来完成一些事情,对于我这种懒人来说当然是希望能简单就简单,这就不得不使用一下git alias这个功能了,通过这个功能可以为较长的命令取一个简短的别名,下面这就是我工作中用到的一些总结

增加git的别名配置

git config --global alias.别名 "命令全称"

查看git中已存在的别名命令(其实本质是查看git的全局配置)

git config --global --list

删除git中的全局配置(比如:别名)

方法一:修改配置文件

  1. 先打开配置文件的编辑界面

    git config --global --edit

会出现以下界面:

[user]
        name = chenwochong
        email = 105736****@qq.com
[core]
        excludesfile = /Users/howie/.gitignore_global
        autocrlf = input
        safecrlf = warn
[difftool "sourcetree"]
        cmd = opendiff \"$LOCAL\" \"$REMOTE\"
        path =
[mergetool "sourcetree"]
        cmd = /Applications/Sourcetree.app/Contents/Resources/opendiff-w.sh \"$LOCAL\" \"$REMOTE\" -ancestor \"$BASE\" -merge \"$MERGED\"
        trustExitCode = true
[alias]
        lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
[filter "lfs"]
        clean = git-lfs clean -- %f
        smudge = git-lfs smudge -- %f
        process = git-lfs filter-process
        required = true
~                                                                                                                                                          
~                                                                                                                                                          
~                                                                                                                                                          
"~/.gitconfig" 20L, 665C
  1. 删除掉对应的配置,再保存退出,完成。

方法二: 直接删除

git config --global --unset alias.别名

eg: git config --global --unset alias.s  # 删除一个名为s的别名

彩色的提交日志

git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"

按照合并数量给贡献者排名

git config --global alias.rank "shortlog -sn --no-merges"

add时先校验

git config --global alias.a "add -p"

简化commit

git config --global alias.cm "commit -m"

查看全局配置

git config --global alias.confall "config --global --list"

无自动合并的pull

git config --global alias.pure "pull --rebase"

取消add添加的文件

git config --global alias.del "restore --staged"

相关文章

网友评论

      本文标题:工作中好用的git alias别名

      本文链接:https://www.haomeiwen.com/subject/ypjgoqtx.html