从PowerShell中调用git命令

3

当我从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调用这些长命令时进行封装?

1
你确定内部命令 git describe --tags --abbrev=0 HEAD^ 单独运行是有效的吗? - Don Cruickshank
1个回答

2
您可以使用$()在字符串内执行替换以使其正常工作。
git log "$(git describe --tags --abbrev=0 HEAD^)..HEAD" --oneline --count

反引号字符在PowerShell中被用作转义字符,就像Unix shell中使用反斜杠一样。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接