程序員都是"懶惰"的,哪怕是執行一個命令的時候少敲了一個字母也感覺特舒坦。Git就允許爲命令設置別名。
以git status爲例,如果敲git st
顯然無法識別。
new-host-2:designer XXX$ git st
git: 'st' is not a git command. See 'git --help'.
Did you mean one of these?
status
reset
stage
stash
svn
我們可以在 ~/.gitconfig 文件裏面進行別名設置,即加上下面這幾行
[alias]
st = status
ci = commit
br = branch
co = checkout
df = diff
接着再敲git st
這次git st 就被識別成 git status了。
new-host-2:designer XXX$ git st # On branch master # Your branch is behind 'origin/master' by 4 commits, and can be fast-forwarded. # nothing to commit (working directory clean)
有些程序員可能會有某幾個單詞敲的特別不習慣,比如總把push敲成psuh,那索性就可以把 psuh 作爲 push 的一個別名加到配置文件中,多省事。