在Powershell中执行git命令

Mar*_*tao 3 git powershell azure-devops

我正在尝试使用Powershell处理VSTS任务中的git脚本,但无法正常工作。

我正在做的是在将最新标签放入发行说明后获取最新的提交消息,这是基本的git命令:

git log `git describe --tags --abbrev=0`..HEAD --no-decorate --no-merges --abbrev=0 --pretty=format:"%s"
Run Code Online (Sandbox Code Playgroud)

但是Powershell不接受这种格式,因此我执行以下操作:

$latestTag = git describe --tags --abbrev=0
$releaseNotes = git log $latestTag..HEAD --no-decorate --no-merges --abbrev=0 --pretty=format:"%s"
Run Code Online (Sandbox Code Playgroud)

似乎当我将变量放在它$latestTag旁边时..HEAD,如果指定了标记,则它会换行。v1.2.9而不是变量,效果很好。

我该怎么做才能使其正常运行?谢谢。

Mar*_*ger 6

您可以将表达式括$latestTag..HEAD"标记中,如下所示:

$latestTag = git describe --tags --abbrev=0
$releaseNotes = git log "$latestTag..HEAD" --no-decorate --no-merges --abbrev=0 --pretty=format:"%s"
Run Code Online (Sandbox Code Playgroud)

这与PowerShell扩展变量的方式有关,但是我使用PS不足以真正理解它。

  • 我猜想它会阻止PowerShell将..解释为范围运算符(即1到10的范围是1..10),而不是字符串。 (2认同)