需求
我經常會在項目根目錄中右鍵點開 Git Bash 進行一些指令行操作,預設視窗中會顯示目前檔案目錄和 git 分支名,但我希望能看到更多資訊,如是否存在未送出的修改、未推送的送出等,這樣我在每天打開 bash 視窗後就能對目前項目的狀态有個大概的了解。
搜尋
我在網上查閱了一番,最終決定使用 bash-git-prompt。
結果
先放上最終的效果對比圖:
預設視窗
安裝
bash-git-prompt
後
相關含義如下(詳情檢視 bash-git-prompt 官方說明):
(master↑3|✚1): on branch master, ahead of remote by 3 commits, 1 file changed but not staged
(status|●2): on branch status, 2 files staged
(master|✚7…): on branch master, 7 files changed, some files untracked
(master|✖2✚3): on branch master, 2 conflicts, 3 files changed
(master|⚑2): on branch master, 2 stash entries
(experimental↓2↑3|✔): on branch experimental; your branch has diverged by 3 commits, remote by 2 commits; the repository is otherwise clean
(:70c2952|✔): not on any branch; parent commit has hash 70c2952; the repository is otherwise clean
複制代碼
實作
找到你安裝 Git 的位址,在
Git/etc
目錄下将 bash-git-prompt 項目 clone 下來:
git clone https://github.com/magicmonty/bash-git-prompt.git
複制代碼
然後用編輯器打開
Git/etc
目錄下的
bash.bashrc
檔案,注釋其中全部代碼,新增如下三行代碼:
GIT_PROMPT_ONLY_IN_REPO=1
GIT_PROMPT_THEME=Evermeet # 主題可以自己選,在 Git\etc\.bash-git-prompt\themes 中挑一個
source /etc/.bash-git-prompt/gitprompt.sh
複制代碼
儲存檔案後,重新打開 Git Bash 視窗,Voila!安裝好了~
問題
如果你發現視窗中的打勾和箭頭等符号顯示有問題,可以這樣做:
右鍵視窗标題欄 -> Options -> Text -> Font Select -> DejaVu Sans Mono
參考:Strange character
The font limitation shows up in the default Ubuntu shell on Windows 10 as well but I was able to see the glyph characters by simply using DejaVu Mono dejavu-fonts.github.io/. What @scotlynhatt means is download the font on windows, install it and then select it from the font menu for the WSL window (right click on the title bar -> properties -> font).