Oh-My-Zsh 操做 Git 的快捷鍵

本篇文章介紹 Oh-My-Zsh 安裝,以及 git 快捷鍵。也許你已經煩透了天天 git add . git commit -m 'some fix' git push...git

若是操做變成這樣 ga . gcmsg 'some fix' gp是否是很炫酷,好吧,對於已經使用的人沒什麼新鮮感。github

接下來針對好奇的 Program development engineer(程序猿),作詳細介紹。shell

相信 git 你們並不陌生,不熟悉 git 操做的能夠看我轉載的一篇阮一峯大神的 經常使用 Git 命令清單,重頭戲 oh-my-zsh 你們能夠看 oh-my-zsh官網編程

Oh-My-Zsh

Oh-My-Zsh is an open source, community-driven framework for managing your ZSH configuration. It comes bundled with a ton of helpful functions, helpers, plugins, themes, and a few things that make you shout...windows

簡單說就是集成插件的命令行工具。針對 Mac 用戶和 Linux 用戶有很好的支持,windows 的朋友先不要急(有彩蛋)。bash

安裝

Mac 用戶和 Linux 用戶經過在您的終端中運行如下命令之一來安裝。能夠安裝經過 curlwget 命令行。curl

via curl工具

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

via wget開發工具

sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"

windows 我推薦一個集成 shell,git,oh-my-zsh 的命令行工具Babun。點擊進入官網下載。固然官網還給出了其餘炫酷功能你們能夠詳細閱讀。url

oh-my-zsh 有許多插件和主題你們能夠去 ~/.zshrc 配置

更多功能能夠去官網閱讀,這裏強烈建議你們使用,由於會提升工做效率,對於追求完美開發體驗的人幫助很大。

快捷鍵實現原理

這裏只說 oh-my-zsh 針對 git 的改進。爲何支持縮寫的形式。

你們可能知道 git 的快捷鍵 alias,它容許咱們本身配製快捷鍵。例如

alias gst='git status'
alias gp='git push'
alias gp='git push'

須要配置的快捷鍵過多,若是對 git 操做了解不夠深刻的人沒法自行配置。那麼 oh-my-zsh 是如何實現的呢?

其實就是用的 alias ,這裏是 Github 上的連接 https://github.com/robbyrusse... ,經過 url 便知這裏的master分支下,plugins插件目錄,git插件下的配置文件。

喜歡閱讀代碼的直接點擊連接查看全部快捷鍵實現。這裏便於整理把平時工做經常使用的快捷鍵給你們,至於不經常使用的你們查看 Github 上的連接,可能記得多了這種對應關係容易弄混,建議你們只熟練記憶工做常有的快捷鍵,其它能夠按着 git 官方文檔去作。減小出錯和沒必要要的麻煩。

經常使用快捷鍵

g - git
gst - git status
gl - git pull
gup - git pull --rebase
gp - git push
gd - git diff
gdc - git diff --cached
gdv - git diff -w "$@" | view
gc - git commit -v
gc! - git commit -v --amend
gca - git commit -v -a
gca! - git commit -v -a --amend
gcmsg - git commit -m
gco - git checkout
gcm - git checkout master
gr - git remote
grv - git remote -v
grmv - git remote rename
grrm - git remote remove
gsetr - git remote set-url
grup - git remote update
grbi - git rebase -i
grbc - git rebase --continue
grba - git rebase --abort
gb - git branch
gba - git branch -a
gcount - git shortlog -sn
gcl - git config --list
gcp - git cherry-pick
glg - git log --stat --max-count=10
glgg - git log --graph --max-count=10
glgga - git log --graph --decorate --all
glo - git log --oneline --decorate --color
glog - git log --oneline --decorate --color --graph
gss - git status -s
ga - git add
gm - git merge
grh - git reset HEAD
grhh - git reset HEAD --hard
gclean - git reset --hard && git clean -dfx
gwc - git whatchanged -p --abbrev-commit --pretty=medium
gsts - git stash show --text
gsta - git stash
gstp - git stash pop
gstd - git stash drop
ggpull - git pull origin $(current_branch)
ggpur - git pull --rebase origin $(current_branch)
ggpush - git push origin $(current_branch)
ggpnp - git pull origin $(current_branch) && git push origin $(current_branch)
glp - _git_log_prettily

就我而言已經足夠了,固然也已經包括了 Github 上大部分快捷鍵。

總結

好的開發工具能夠大大提高工做效率,應用適立即可,過多依賴快捷鍵自動補全之類的工具時間久了基礎知識退化,致使沒有好用的工具沒法編程,建議新人熟記原始命令後再嘗試快捷鍵,避免錯誤的發生(畢竟這是管理代碼工具,操做不當極可能刪除了最近 add 以前或者 commit 以前的代碼快照,由於某些操做是不可逆的),親身踩過坑刪除了一天的工做,雖然重寫兩個小時就完成,但十分不爽。

哈哈,牢騷了一下,本人如今大四在校生,實習5個月,哪裏寫的不對還望你們指正。

文章出自 orange 的 我的博客 http://orangexc.xyz/

相關文章
相關標籤/搜索