自動補(bǔ)全
適用環(huán)境(bash)
下載Git源碼 Github地址
進(jìn)入目錄contrib/completion目錄,會看到一個(gè)git-completion.bash文件。將此文件復(fù)制到你自己的用戶主目錄中(cp git-completion.bash ~/.git-completion.bash),并把下面一行內(nèi)容添加到你的 .bash_profile 文件中:
source ~/.git-completion.bash
設(shè)置系統(tǒng)上所有用戶都設(shè)置默認(rèn)此腳本
Mac 上將此腳本復(fù)制到 /opt/local/etc/bash_completion.d 目錄中,
Linux 上則復(fù)制到 /etc/bash_completion.d/ 目錄中。這兩處目錄中的腳本,都會在 Bash 啟動時(shí)自動加載
--安裝完成--
使用方法連續(xù)敲擊兩次TAB鍵
$ git co<tab><tab>
commit config
GIT命令別名
有偷懶何樂而不為。
git的alias是通過配置文件進(jìn)行定制的,這個(gè)配置文件能做的事情還有很多,這里只介紹alias部分,config配置文件
git的用戶配置文件一般在做~/.gitconfig,當(dāng)前倉庫的配置文件是.git目錄下的config文件。
git config添加
加上--global,配置當(dāng)前用戶的配置文件~/.gitconfig
可以在任何目錄下執(zhí)行git config --global操作
$ git config --global alias.st status
不加--global默認(rèn)配置當(dāng)前項(xiàng)目的配置文件
需要在git的目錄下操作,否則會報(bào)如下的錯(cuò)
$ git config alise.st status
fatal: not in a git directory
git(項(xiàng)目)目錄下
$ git config alias.st status
- 編輯
~/.gitconfig
在[alias]模塊下添加,如果沒有[alias]模塊新建alias模塊。
$ vim ~/.gitconfig
[alias]
st = status
使用
# 查看狀態(tài)
$ git status
or
$ git st
# 查看分支
$ git branch
or
$ git br
備注: log詳情參考
[alias]
st = status
br = branch
cm = commit
co = checkout
lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
用shell的別名
以git status為例
git的別名: git st,前必須要加上git
shell別名: gs,命令是不是簡單很多
下面看下shell里git別名的簡單配置
Bash 內(nèi)置命令 alias 用于創(chuàng)建一個(gè)別名,創(chuàng)建別名的語法:
alias name='command'
vim 打開 ~/.bash_profile, 在末尾添加以下格式的內(nèi)容(下面是自己測試使用,根據(jù)自己使用習(xí)慣做相應(yīng)的修改、添加等),保存退出運(yùn)行 source ~/.bash_profile
alias gs="git status"
alias gc="git checkout"
alias gl="git lg"
alias gb="git branch"
alias gba="git branch -a"
使用
$ gb
* du
master
$ gba
* du
master
remotes/origin/du
remotes/origin/jeffchen
remotes/origin/master