备注:
本文参考于廖雪峰老师的博客Git教程。按照其博客进行学习和记录,感激其自私分享,也欢送各位查看原文。
配置别名
如果,如果这么神器的Git版本控制系统,能够简化命令。比方git status
,间接用git st
代替,几乎爽翻天。
通过为Git命令配置别名,就能实现st
示意status
,如下:
$ git config --global alias.st status
此时git st
就示意git status
据此能够简化更多命令,比方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
是全局参数,配置的别名能够在以后计算机下应用。
unstage
别名
再比方撤销暂存区批改的命令git reset HEAD file
是一个unstage
操作,则能够unstage
别名:
$ git config --global alias.unstage 'reset HEAD'
git last
别名
比方配置git last
,显示最初一次提交信息:
$ git config --global alias.last 'log -1'
这样,用git last就能显示最近一次的提交:
甚至还有人丧心病狂地把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
的成果能够应用不同色彩标识出log记录,看起来十分炫
配置文件
Git的配置,加上--global
是针对以后用户起作用的,如果不加,那只针对以后的仓库起作用。
- git配置文件的地位
每个仓库的Git配置文件都放在.git/config
文件中:
如下为廖雪峰老师博客中展现的
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
文件 中。
linux零碎用户目录在home
目录下查看
Windows用户目录为C:C:\Users\用户名
,通过%USERPROFILE%
或%HOMEPATH%
间接拜访即可
$ cat .gitconfig[user] name = Your Name email = your@email.com[core] autocrlf = false[filter "lfs"] clean = git-lfs clean -- %f smudge = git-lfs smudge -- %f process = git-lfs filter-process required = true