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

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

问题描述

基本上我是在这个之后,但是对于PowerShell而不是bash。



我通过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屋!

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