--- title: Git自訂常用指令配置 tags: Git --- <style> .red{ color: red; } .orange{ color: #ff5733; } .blue{ color: #3383ff; } </style> # Git自訂常用指令配置 紀錄筆者常用指令簡化操作配置,不定期更新內容。 使用`git config`進行設置。 設置命令規格: git config <font class='red'>--global</font> <font class='orange'>alias</font>.<font class='orange'><自訂命令名稱></font> <font class='blue'> <command> </font> * <font class=red>--global</font> 代表全域通用,針對範圍限制在當前git目錄,可以改為<font class=red>--local</font>。 * 如果對應git命列有待入參數,需使用單引號將整個<font class='blue'> <command> </font>包覆起來。 ### 如何使用自訂指令 以[Git Log - 查看目前分支最後提交一筆commit紀錄](https://hackmd.io/Jwv3aYcgSnKJYfoWPdcyXg?view#%E6%9F%A5%E7%9C%8B%E7%9B%AE%E5%89%8D%E5%88%86%E6%94%AF%E6%9C%80%E5%BE%8C%E6%8F%90%E4%BA%A4%E4%B8%80%E7%AD%86commit%E7%B4%80%E9%8C%84---gt-git-last)為例,簡化指令名稱為`last`,完整指令下法如下 ```shell= git last ``` --- ## Git Log ### 美化所有Log輸出成一列,並帶入圖形軌跡 --> `git cma` ```shell= git config --global alias.cma 'log --pretty=oneline --graph --decorate --all' ``` * 原始指令 --> `git log --pretty=oneline --graph --decorate --all` * 簡化指令 --> `git cma` ### 查看目前分支最後提交一筆commit紀錄 --> `git last` ```shell= git config --global alias.last 'log -1 HEAD' ``` * 原始指令 --> `git log -1 HEAD` * 簡化指令 --> `git last` ## Git Commit ### Commit -m 新增一筆Commit ```shell= git config --global alias.com 'commit -m' ``` ## Git Cherry-Pick ### Cherry-Pick指令簡化 --> `git cp` ```shell= git config --global alias.cp 'cherry-pick' ``` * 原始指令 --> `git cherry-pick <CommitId>` * 簡化指令 --> `git cp <CommitId>` ### Cherry-Pick持續整合(解完衝突)指令簡化 --> `git cpc` ```shell= git config --global alias.cpc 'cherry-pick --continue' ``` * 原始指令 --> `git cherry-pick --continue` * 簡化指令 --> `git cpc` ### Cherry-Pick取消此次整合指令簡化 --> `git cpa` ```shell= git config --global alias.cpa 'cherry-pick --abort' ``` * 原始指令 --> `git cherry-pick --abort` * 簡化指令 --> `git cpa` ## Git Checkout ### Checkout指令簡化 --> `git ck` ```shell= git config --global alias.ck 'checkout' ``` * 原始指令 --> `git checkout <本地分支>` * 簡化指令 --> `git ck <本地分支>` ### 建立新分支指令簡化 --> `git cb` ```shell= git config --global alias.cb 'checkout -b' ``` * 原始指令 --> `git checkout -b <本地分支> <來源分支>` * 簡化指令 --> `git cb <本地分支> <來源分支>` ## Git Push ### 上傳新分支(遠端上還未有對應分支)指令簡化 --> `git puo` ```shell= git config --global alias.puo 'push -u origin' ``` * 原始指令 --> `git push -u origin <本地分支>` * 簡化版 --> `git puo <本地分支>` ## Git Merge ### Merge指令簡化 --> `git me` ```shell= git config --global alias.me 'merge' ``` * 原始指令 --> `git merge <來源分支>` ### Merge持續合併(解完衝突)指令簡化 --> `git mec` ```shell= git config --global alias.mec 'merge --continue' ``` * 原始指令 --> `git merge --continue` ### Merge取消此次整合指令簡化 --> `git mea` ```shell= git config --global alias.mea 'merge --abort' ``` * 原始指令 --> `git merge --abort` ## Git Stash ### Stash暫存列表資訊 --> `git stls` ```shell= git config --global alias.stls 'stash list' ``` * 原始指令 --> `git stash list` * 簡化指令 --> `git stls` ### Stash暫存儲存一筆 --> `git sts` ```shell= git config --global alias.sts 'stash save' ``` * 原始指令 --> `git stash save <暫存標題>` * 簡化指令 --> `git sts <暫存標題>` ### Stash暫存刪除一筆 --> `git std` ```shell= git config --global alias.std 'stash drop' ``` * 原始指令 --> `git stash drop` * 簡化指令 --> `git std <暫存編號>`