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):

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

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

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

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


书籍推荐