A1.6 附录 A: 其它环境中的 Git - Powershell 中的 Git

Powershell 中的 Git

Windows 中的普通命令行终端 (cmd.exe) 无法自定义 Git 使用体验,但是如果你正在使用 Powershell,那么你就十分幸运了。一个名为 Posh-Git (https://github.com/dahlbyk/posh-git) 的扩展包提供了强大的 tab 补全功能, 并针对提示符进行了增强,以帮助你聚焦于你的仓库状态。它看起来像:

附带了 Posh-Git 扩展包的 Powershell。

Figure 165. 附带了 Posh-Git 扩展包的 Powershell。

如果你已经在 Windows 上安装了 GitHub,Posh-Git 也会被安装,你只需要添加以下两行到你的 profile.ps1 文件 (文件位于 C:\Users\<username>\Documents\WindowsPowerShell):

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

如果你没有在 Windows 上安装 GitHub,只需要从 (https://github.com/dahlbyk/posh-git) 下载一份 Posh-Git 发行版,并且解压至 WindowsPowershell 目录。然后以管理员权限打开 Powershell 提示符,并且执行下面的命令:

  1. > Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Confirm
  2. > cd ~\Documents\WindowsPowerShell\posh-git
  3. > .\install.ps1

它将会向你的 profile.ps1 文件添加适当的内容,Posh-Git 将会在下次打开提示符时被启用。

prev | next

原文: https://git-scm.com/book/zh/v2/%E9%99%84%E5%BD%95-A%3A-%E5%85%B6%E5%AE%83%E7%8E%AF%E5%A2%83%E4%B8%AD%E7%9A%84-Git-Powershell-%E4%B8%AD%E7%9A%84-Git