在Mac Bash中显示git分支和状态

Doz*_*zer 14 git macos bash

我使用Github for windows客户端.使用powershell的shell非常好!

在此输入图像描述

我如何在MAC上实现它?不仅是分支名称,我也想要git status

djr*_*ero 27

Git本身有这个:https://raw.github.com/git/git/master/contrib/completion/git-prompt.sh

使用范例:

GIT_PS1_SHOWUPSTREAM="auto"
GIT_PS1_SHOWCOLORHINTS="yes"
source ~/.git-prompt.sh

export PROMPT_COMMAND='__git_ps1 "\u@\h:\W" "\\\$ ";'
Run Code Online (Sandbox Code Playgroud)

它看起来像这样:

在此输入图像描述

绿色名称是分支,右括号前的符号是状态.

  • 您需要将djromero的使用示例放入〜/ .bash_profile.默认情况下你可能在Mac上没有,所以你需要创建文件,然后逐字使用(假设git-prompt.sh保存在〜/ .git-prompt.sh). (2认同)

Doz*_*zer 7

我认为 ohmyzsh 是我最好的选择\xef\xbc\x81

\n\n

https://github.com/robbyrussell/oh-my-zsh

\n

  • oh-my-zsh 对于 git 的这个好处来说是非常具有侵入性的 (9认同)

K Z*_*K Z 6

vcprompt为Git(以及Hg,Bazaar和SVN)提供类似的shell提示.您可以通过homebrew以下方式安装:

brew install vcprompt
Run Code Online (Sandbox Code Playgroud)