如何在我的 PowerShell 提示符中显示我当前的 git 分支名称? [英] How can I display my current git branch name in my PowerShell prompt?

查看:97
本文介绍了如何在我的 PowerShell 提示符中显示我当前的 git 分支名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我在这个之后,但对于PowerShell而不是重击.

Basically I'm after this but for PowerShell instead of bash.

我通过 PowerShell 在 Windows 上使用 git.如果可能,我希望我当前的分支名称显示为命令提示符的一部分.

I use git on windows through PowerShell. If possible, I'd like my current branch name to displayed as part of the command prompt.

推荐答案

更简单的方法是安装 Powershell 模块 豪华混帐.它开箱即用,带有所需的提示:

An easier way would be just installing the Powershell module posh-git. It comes out of the box with the desired prompt:

提示

PowerShell 通过执行一个提示函数来生成它的提示(如果存在的话).posh-git 在 profile.example.ps1 中定义了这样一个函数,它输出当前工作目录,后跟一个缩写的 git 状态:

PowerShell generates its prompt by executing a prompt function, if one exists. posh-git defines such a function in profile.example.ps1 that outputs the current working directory followed by an abbreviated git status:

C:UsersKeith [master]>

默认情况下,状态摘要具有以下格式:

By default, the status summary has the following format:

[{HEAD-name} +A ~B -C !D |+E ~F -G !H]

(对于安装 posh-git 我建议使用 psget)

(For installing posh-git I suggest using psget)

如果您没有 psget,请使用以下命令:

If you don't have psget use the following command:

(new-object Net.WebClient).DownloadString("https://raw.githubusercontent.com/psget/psget/master/GetPsGet.ps1") | iex

要安装 posh-git,请使用以下命令:安装模块 posh-git

To install posh-git use the command: Install-Module posh-git

为了确保为每个 shell 加载 posh-git,请使用 Add-PoshGitToProfile 命令.

To ensure posh-git loads for every shell, use the Add-PoshGitToProfile command.

这篇关于如何在我的 PowerShell 提示符中显示我当前的 git 分支名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆