备注:

本文参考于廖雪峰老师的博客Git教程。按照其博客进行学习和记录,感激其自私分享,也欢送各位查看原文。

配置别名

如果,如果这么神器的Git版本控制系统,能够简化命令。比方git status,间接用git st代替,几乎爽翻天。

通过为Git命令配置别名,就能实现st示意status,如下:

$ git config --global alias.st status

此时git st就示意git status

据此能够简化更多命令,比方co示意checkoutci示意commitbr示意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