git 怎么起别名
来源:互联网 发布:2017年淘宝一颗钻 编辑:程序博客网 时间:2024/05/02 16:45
原文:http://www.liaoxuefeng.com/
有没有经常敲错命令?比如git status
?status
这个单词真心不好记。
如果敲git st
就表示git status
那就简单多了,当然这种偷懒的办法我们是极力赞成的。
我们只需要敲一行命令,告诉Git,以后st
就表示status
:
$ git config --global alias.st status
好了,现在敲git st
看看效果。
当然还有别的命令可以简写,很多人都用co
表示checkout
,ci
表示commit
,br
表示branch
:
$ git config --global alias.co checkout$ git config --global alias.ci commit$ git config --global alias.br branch
以后提交就可以简写成:
$ git ci -m "bala bala bala..."
--global
参数是全局参数,也就是这些命令在这台电脑的所有Git仓库下都有用。
在撤销修改一节中,我们知道,命令git reset HEAD file
可以把暂存区的修改撤销掉(unstage),重新放回工作区。既然是一个unstage操作,就可以配置一个unstage
别名:
$ git config --global alias.unstage 'reset HEAD'
当你敲入命令:
$ git unstage test.py
实际上Git执行的是:
$ git reset HEAD test.py
配置一个git last
,让其显示最后一次提交信息:
$ git config --global alias.last 'log -1'
这样,用git last
就能显示最近一次的提交:
$ git lastcommit adca45d317e6d8a4b23f9811c3d7b7f0f180bfe2Merge: bd6ae48 291bea8Author: Michael Liao <askxuefeng@gmail.com>Date: Thu Aug 22 22:49:22 2013 +0800 merge & fix hello.py
甚至还有人丧心病狂地把lg
配置成了:
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 lg
的效果:
为什么不早点告诉我?别激动,咱不是为了多记几个英文单词嘛!
配置文件
配置Git的时候,加上--global
是针对当前用户起作用的,如果不加,那只针对当前的仓库起作用。
配置文件放哪了?每个仓库的Git配置文件都放在.git/config
文件中:
$ cat .git/config [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true ignorecase = true precomposeunicode = true[remote "origin"] url = git@github.com:michaelliao/learngit.git fetch = +refs/heads/*:refs/remotes/origin/*[branch "master"] remote = origin merge = refs/heads/master[alias] last = log -1
别名就在[alias]
后面,要删除别名,直接把对应的行删掉即可。
而当前用户的Git配置文件放在用户主目录下的一个隐藏文件.gitconfig
中:
$ cat .gitconfig[alias] co = checkout ci = commit br = branch st = status[user] name = Your Name email = your@email.com
配置别名也可以直接修改这个文件,如果改错了,可以删掉文件重新通过命令配置。
0 0
- git 怎么起别名
- Git学习笔记2 给git命令起别名
- bash 起别名
- git别名
- 为命名空间起别名
- 143,为数据类型起别名
- typedef给数据类型起别名
- update语句起别名写法
- 关于Oracle数据库起别名
- git设置命令别名
- git 取别名 alias
- Git之配置别名
- git配置别名
- git 命令别名配置
- git 命令别名
- Git 配置别名
- Git 命令别名
- Git配置别名
- 引用头文件的的放置
- Tomcat环境变量配置win10
- 程序易错location
- Android的四大组件的理解
- Java中JVM详解
- git 怎么起别名
- 学习资料 字符串
- HBase
- C#未将对象引用设置到对象的实例
- Documentum基础知识
- linux系统下的/var/spool/mail/root
- 爱丁堡大学神经机器翻译系统 nematus 使用笔记
- Properties 持久的属性集
- python 多线程批量操作数据库测试