重启后如何使用(Windows Powershell)GitShell命令历史记录?
How to use (Windows Powershell) GitShell commands history after restart?
我正在使用从官方 Github 网站下载的 windows (7) Gitshell (Powershell)。重启后如何使用历史命令?
命令 exit
而不是 x
无效(如建议 here)
看不到任何 ~/.bash_profile
或 ~/.bash_history
文件(让它看起来像 here)
PowerShell 没有持久的历史记录。你可以(有点)save/restore自己使用这样的命令历史记录:
Get-History | Export-Clixml 'C:\path\to\history.xml'
Import-Clixml 'C:\path\to\history.xml' | Add-History
使用Get-History
to list the history and Invoke-History
to invoke a command from the history. The save and restore can be automated by putting something like this into your PowerShell profile:
Register-EngineEvent -SourceIdentifier PowerShell.Exiting -Action {
Get-History | Export-Clixml "$env:USERPROFILE\ps_history.xml"
} | Out-Null
if (Test-Path -LiteralPath "$env:USERPROFILE\ps_history.xml") {
Import-Clixml "$env:USERPROFILE\ps_history.xml" | Add-History
}
但是,这不会使 "historical" 命令可通过光标键使用。如果你想要,你需要 运行 PowerShell 类似 Console2, ConEmu, or Clink.
我正在使用从官方 Github 网站下载的 windows (7) Gitshell (Powershell)。重启后如何使用历史命令?
命令
exit
而不是x
无效(如建议 here)看不到任何
~/.bash_profile
或~/.bash_history
文件(让它看起来像 here)
PowerShell 没有持久的历史记录。你可以(有点)save/restore自己使用这样的命令历史记录:
Get-History | Export-Clixml 'C:\path\to\history.xml'
Import-Clixml 'C:\path\to\history.xml' | Add-History
使用Get-History
to list the history and Invoke-History
to invoke a command from the history. The save and restore can be automated by putting something like this into your PowerShell profile:
Register-EngineEvent -SourceIdentifier PowerShell.Exiting -Action {
Get-History | Export-Clixml "$env:USERPROFILE\ps_history.xml"
} | Out-Null
if (Test-Path -LiteralPath "$env:USERPROFILE\ps_history.xml") {
Import-Clixml "$env:USERPROFILE\ps_history.xml" | Add-History
}
但是,这不会使 "historical" 命令可通过光标键使用。如果你想要,你需要 运行 PowerShell 类似 Console2, ConEmu, or Clink.