当我从PowerShell脚本调用git时,当我运行更复杂的命令时,我开始遇到问题:
# Work fine
git log
# Gives error
git log `git describe --tags --abbrev=0 HEAD^`..HEAD --oneline --count
错误:
fatal: ambiguous argument 'git': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
从PowerShell调用这些长命令时,有没有一种好方法可以封装它们?
您可以使用 $()
在字符串中执行替换以使其正常工作。
git log "$(git describe --tags --abbrev=0 HEAD^)..HEAD" --oneline --count
反引号字符在PowerShell中用作转义字符,就像Unix shell中使用反斜杠一样。