Git一些其它的功能

Git 开始之前我们配置过user.name和user.email.其实还有很多其他的配置项

例如:让Git显示颜色,会让命令输出来更醒目:

$ git config --global color.ui true  

配置别名 

有没有经常敲错命令的?比如git status?

我们可以给命令起个别名

LV@LV-PC MINGW32 ~
$ git config --global alias.st status

LV@LV-PC MINGW32 /c/gitskill (master)
$ git st
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean

LV@LV-PC MINGW32 /c/gitskill (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean

是不是git st 和git status的执行结果一样呢?

当然还可以简写很多命令,很多人都用co表示checkout,ci表示commit,br表示branch

LV@LV-PC MINGW32 /c/gitskill (master)
$ git config --global alias.ci commit

LV@LV-PC MINGW32 /c/gitskill (master)
$ git config --global alias.co checkout

LV@LV-PC MINGW32 /c/gitskill (master)
$ git config --global alias.br branch

--global参数是全局参数,也就是这些命令在这台电脑上的所有Git仓库都有用

$ git config --global --list
user.email=lvloveyuforever@gmail.com
user.name=mars
alias.st=status
alias.co=checkout
alias.ci=commit
alias.br=branch

在撤销修改一节中,命令git reset HEAD file可以把暂存区的修改撤销掉(unstage),重新放回工作区,既然是一个unstage操作,

就可以配置一个unstage别名:

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

当你敲入命令:

$ git unstage test.txt

相当于执行了:

$ git reset HEAD test.txt

配置一个git last 让其显示最后一次信息

$ git config --global alias.last 'log -1'

简化命令,自己看着怎么好记,就怎么玩

像把git config --global alias.lg "log --graph --pretty=oneline --abbrev-commit"

原文地址:https://www.cnblogs.com/LvLoveYuForever/p/5527275.html