Powershell 如何从自定义shell使用GitHub for Windows附带的posh git?

Powershell 如何从自定义shell使用GitHub for Windows附带的posh git?,powershell,github-for-windows,posh-git,Powershell,Github For Windows,Posh Git,安装GitHub for Windows是一种很好的方法,可以同时获得初学者的git Windows应用程序、msysgit和posh git,但是您只能通过调用“GitHub.appref-ms--open shell”使用posh git启动git shell 我想做的是启动一个控制台,加载powershell,并使用Github for Windows附带的posh git,但我想不出一种方法将其加载到powershell中 更新:我不想单独安装Git for Windows,因为已经安装

安装GitHub for Windows是一种很好的方法,可以同时获得初学者的git Windows应用程序、msysgit和posh git,但是您只能通过调用“GitHub.appref-ms--open shell”使用posh git启动git shell

我想做的是启动一个控制台,加载powershell,并使用Github for Windows附带的posh git,但我想不出一种方法将其加载到powershell中

更新:我不想单独安装Git for Windows,因为已经安装了msysgit

通过从AppData\Local\Github文件夹调用shell1.ps1脚本,我取得了一些进展,它确实允许我调用git。但它不会显示我所在的分支,与GitHub for Windows的“Git Shell”相对。

从,将此内容放入您的配置文件中,从GitHub for Windows加载posh Git:

# If Posh-Git environment is defined, load it.
if (test-path env:posh_git) {
    . $env:posh_git
}

尽管@dahlbyk的回答没有提供解决方案,但它仍然将我推向了正确的方向。问题是,Phil的Haack博客文章中引用的$env:posh git环境没有定义,因此在PowerShell概要文件脚本中测试它没有任何作用

但有效的方法是从同一脚本运行shell.ps1和profile.example.ps1。以下是像我这样的PowerShell noobs的配方:

  • 在活动用户的Documents\WindowsPowerShell文件夹中编辑或创建Microsoft.PowerShell\u profile.ps1(如果该文件夹不存在,请创建该文件夹)
  • 添加以下两行:

    . (Resolve-Path "$env:LOCALAPPDATA\GitHub\shell.ps1")
    . $env:github_posh_git\profile.example.ps1
    
  • ,要在powershell中安装和使用Posh git,请执行以下操作:

  • git克隆git://github.com/dahlbyk/posh-git.git
    到您选择的目录
  • 允许使用以下任一方式执行脚本:
  • Set ExecutionPolicy RemoteSigned
  • 设置执行策略不受限制
  • cd posh git
  • \install.ps1
  • $个人资料

  • 我最初遵循流行教程中给出的指导(正如@dahlbyk和@CB所指出的),但与OP有类似的问题。

    这个链接有帮助吗@Christian-不,请参阅更新的问题有没有办法防止它强迫我登录每个命令?这种方法也在Git文档中有记录。对于想要使用Posh Git的Console2/ConsoleZ选项卡的人,这里有一个快捷方式。将选项卡的Shell属性设置为:
    %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe-NoExit-Command“&{(解析路径“$env:LOCALAPPDATA\GitHub\Shell.ps1”);。$env:GitHub\u posh\u git\profile.example.ps1;}”