在管道命令中使用Powershell参数

时间:2015-04-29 10:26:20

标签: git powershell

我有这个Powershell脚本,它遍历此文件夹的目录并运行git log

但是我无法弄清楚如何将$author参数传递给git命令。

Param(
  [string]$author,
  [string]$since
)
Get-ChildItem | ? { $_.PSIsContainer } | % { Push-Location $_.FullName; Write-Host "--" (Get-Location);`
git --no-pager log --author=$author --since='1 friday ago' --until='now' --format='%Cgreen%cr%Creset %s%Creset' --graph --decorate;`
Pop-Location }

1 个答案:

答案 0 :(得分:1)

鉴于此脚本:

# Log.ps1
Param(
    [string]$author
)

Get-ChildItem -Directory | % { Push-Location $_.FullName; git --no-pager log --author=$author; Pop-Location }

像这样调用它会产生正确的结果:

.\Log.ps1 "SomeAuthor"
相关问题