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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16536512/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 05:25:59  来源:igfitidea点击:

Show git branch and status in Mac Bash

macosgitbash

提问by Dozer

I use the Github for windows client.The shell with powershell is very nice!

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

enter image description here

在此处输入图片说明

How do I implement it on MAC? Not only the branch name,I also want git status

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

采纳答案by Dozer

I think ohmyzsh is my best choose!

我觉得ohmyzsh是我最好的选择!

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

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

回答by djromero

Git itself has this: https://raw.github.com/git/git/master/contrib/completion/git-prompt.sh

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

Usage sample:

使用示例:

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

export PROMPT_COMMAND='__git_ps1 "\u@\h:\W" "\$ ";'

It looks like this:

它看起来像这样:

enter image description here

在此处输入图片说明

The green name is the branch, the symbol before the closing parenthesis is the status.

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

回答by K Z

vcpromptoffers similar shell prompt for Git (and Hg, Bazaar and SVN). You can install it via homebrew:

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

brew install vcprompt