如何在我的PowerShell提示符中显示当前的git分支名称? [英] How can I display my current git branch name in my PowerShell prompt?
问题描述
我通过PowerShell在窗口上使用git。如果可能的话,我希望我的当前分支名称显示为命令提示符的一部分。
更简单的方法是只需安装Powershell模块 posh-git 。它提供了所需的提示框:
提示
PowerShell通过执行提示功能(如果存在)生成提示。 posh-git在profile.example.ps1中定义了这样一个函数,它输出当前工作目录,后面跟着缩写的git状态:
C:\\ \\ Users \\ Keith [master]>
默认状态摘要的格式如下:
[{HEAD-name} + A〜B -C!D | (E-F -G!H)
(对于安装posh-git,我建议使用 psget )
如果您没有psget,请使用以下命令:
(new-object Net.WebClient).DownloadString(http://psget.net/GetPsGet.ps1 )| iex
要安装posh-git,请使用以下命令:
安装-Module posh-git
为了确保每个shell的posh-git加载,请使用 Add-PoshGitToPrompt
命令。
Basically I'm after this but for PowerShell instead of bash.
I use git on windows through PowerShell. If possible, I'd like my current branch name to displayed as part of the command prompt.
An easier way would be just installing the Powershell module posh-git. It comes out of the box with the desired prompt:
The Prompt
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:\Users\Keith [master]>
By default, the status summary has the following format:
[{HEAD-name} +A ~B -C !D | +E ~F -G !H]
(For installing posh-git I suggest using psget)
If you don't have psget use the following command:
(new-object Net.WebClient).DownloadString("http://psget.net/GetPsGet.ps1") | iex
To install posh-git use the command:
Install-Module posh-git
To ensure posh-git loads for every shell, use the Add-PoshGitToPrompt
command.
这篇关于如何在我的PowerShell提示符中显示当前的git分支名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!