gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 11:04:40 27 4
gpt4 key购买 nike

安装适用于 Windows 的 GitHub 是立即获得初学者的 git Windows 应用程序、msysgit 和 posh-git 的好方法 - 但您只能通过调用“GitHub.appref-ms --open-shell”来使用 posh-git 启动 git shell。

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

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

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

最佳答案

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

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

  • 在事件用户的 Documents\WindowsPowerShell 文件夹中编辑或创建 Microsoft.PowerShell_profile.ps1(如果该文件夹不存在,则创建该文件夹)
  • 添加以下两行:
    . (Resolve-Path "$env:LOCALAPPDATA\GitHub\shell.ps1")
    . $env:github_posh_git\profile.example.ps1
  • 关于powershell - 如何从自定义 shell 使用 GitHub for Windows 附带的 posh-git?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12504649/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com