关于git:Git别名和配置文件

8次阅读

共计 1537 个字符,预计需要花费 4 分钟才能阅读完成。

备注:

本文参考于廖雪峰老师的博客 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
正文完
 0