【问题标题】:How to use posh-git that comes with GitHub for Windows from custom shell?如何从自定义 shell 使用 GitHub for Windows 附带的 posh-git?
【发布时间】:2012-09-12 08:21:58
【问题描述】:

安装适用于 Windows 的 GitHub 是立即获得初学者的 git Windows 应用程序 msysgit 和 posh-git 的好方法 - 但您只能通过调用“GitHub.appref-ms --open-”来使用 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”相反。

【问题讨论】:

标签: powershell github-for-windows posh-git


【解决方案1】:

虽然@dahlbyk 的回答没有提供解决方案,但它仍然把我推向了正确的方向。问题是,Phil 的 Haack 博客文章中引用的 $env:posh-git 环境未定义,因此在 PowerShell 配置文件脚本中对其进行测试没有任何作用。

但有效的是从同一个脚本运行 shell.ps1 和 profile.example.ps1。这是像我这样的 PowerShell 菜鸟的秘诀:

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

    . (Resolve-Path "$env:LOCALAPPDATA\GitHub\shell.ps1")
    . $env:github_posh_git\profile.example.ps1
    

【讨论】:

  • 有没有办法阻止它强制我登录每个命令?
  • 这种方法也记录在 Git Docs git-scm.com/book/en/v2/…
  • 这里是任何想要 Posh-Git 的 Console2 / ConsoleZ 选项卡的人的快捷方式。将选项卡的 Shell 属性设置为:%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -NoExit -Command "&{ . (Resolve-Path "$env:LOCALAPPDATA\GitHub\shell.ps1"); . $env:github_posh_git\profile.example.ps1;}"
【解决方案2】:

来自http://haacked.com/archive/2012/05/21/introducing-github-for-windows.aspx,将其放入您的个人资料中以从 GitHub for Windows 加载 posh-git:

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

【讨论】:

    【解决方案3】:

    Following these directions,要在 powershell 中安装和使用 Posh-git,请执行以下操作:

    1. git clone git://github.com/dahlbyk/posh-git.git 到您选择的目录
    2. 允许使用以下任一方式执行脚本:
      1. Set-ExecutionPolicy RemoteSigned
      2. Set-ExecutionPolicy Unrestricted
    3. cd posh-git
    4. .\install.ps1
    5. . $PROFILE

    我最初遵循流行的 haacked.com 教程中给出的指导(正如 @dahlbyk 和 @CB 所指出的那样),但遇到了与 OP 类似的问题。

    【讨论】:

      猜你喜欢
      • 2016-04-29
      • 2014-09-23
      • 1970-01-01
      • 2012-06-25
      • 2013-01-05
      • 1970-01-01
      • 2013-11-11
      • 2017-12-18
      • 1970-01-01
      相关资源
      最近更新 更多