Conda 环境名称在 Powershell 中 conda init 后隐藏 git 分支

Woo*_*193 7 git powershell conda

我为 Powershell 安装了 Posh-Git 模块,最近我还安装了 Anaconda 并执行了conda init. 显然,这profile.ps1通过添加以下代码来修改文件:

#region conda initialize
# !! Contents within this block are managed by 'conda init' !!
(& "{User}\anaconda3\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | Invoke-Expression
#endregion
Run Code Online (Sandbox Code Playgroud)

这确实让我看到了我正在使用的 conda 环境,但它也隐藏了我正在使用的 Git 分支。我该如何修改它以便我可以看到两者?

Fau*_*ter 11

posh-git文档声明 posh-git 不会修改自定义提示。因此,当您Import-Module posh-git在 conda 初始化后运行时,您不会看到任何变化。解决方案是将文件Import-Module posh-git中的 conda 初始化块放在前面,$Profile.CurrentUserAllHosts如下所示:

Import-Module posh-git

#region conda initialize
# !! Contents within this block are managed by 'conda init' !!
(& "{User}\anaconda3\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | Invoke-Expression
#endregion
Run Code Online (Sandbox Code Playgroud)

还值得注意的是,当您运行时Add-PoshGitToProfile,它会将该Import-Module posh-git行添加到您的$Profile.CurrentUserCurrentHost文件中。由于此命令在 后 $Profile.CurrentUserAllHosts执行,因此该命令不会产生任何明显的效果。