防止 VSCode 在 PowerShell 历史记录中保存 GIT 命令

问题描述

我的 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

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...