问题描述
我的 PowerShell 历史记录被来自 VSCode 或其 GitLens 扩展的 GIT 命令污染(自从 GitLens 移至源代码控制面板后,不确定是哪一个实际执行了此操作),例如 git branch --delete
。
有什么办法可以避免吗?
解决方法
这不是真正的预防,而是对症解决。您可以使用 Clear-History 删除与现有条件匹配的命令。然后,这将成为现有历史记录的一部分,以便轻松快速地执行。
也许,
Clear-History -CommandLine *git*
一个更清晰的例子:
Get-History
Id CommandLine
-- -----------
1 Set-Location C:\Test\
2 Get-Command Clear-History
3 Get-Command Clear-History -Syntax
4 Get-Command Clear-History -ShowCommandInfo
5 Get-Help Get-Alias
6 Get-Command Get-ChildItem -Syntax
7 Get-Help Clear-History
Clear-History -CommandLine *Help*,*Syntax
Get-History
Id CommandLine
-- -----------
1 Set-Location C:\Test\
2 Get-Command Clear-History
4 Get-Command Clear-History -ShowCommandInfo
8 Clear-History -CommandLine *Help*,*Syntax