git学习日记二十二(配置)

发布时间:2016-05-26 浏览次数:2794 文章来源:个人博客

有没有经常敲错命令?比如git statusstatus这个单词真心不好记。

如果敲git st就表示git status那就简单多了,当然这种偷懒的办法我们是极力赞成的。


我们只需要敲一行命令,告诉Git,以后st就表示status

$ git config --global alias.st status

好了,现在敲git st看看效果。


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


配置文件

  配置Git的时候,加上--global是针对当前用户起作用的,如果不加,那只针对当前的仓库起作用。

 

配置文件放哪了?每个仓库的Git配置文件都放在.git/config文件中:

$ cat .git/config 
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true[remote "origin"]
    url = [email protected] */" _ue_custom_node_="true">: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 = [email protected] */" _ue_custom_node_="true">

配置别名也可以直接修改这个文件,如果改错了,可以删掉文件重新通过命令配置。


本文来源:廖雪峰的官方网站(http://www.liaoxuefeng.com)

key-word
git配置 git配置文件 git文件配置