我想在我的 PowerShell 脚本中使用 SVN 命令。
我知道我需要将 SVN 可执行文件声明为变量,但之后我想提交一个已声明为变量的文件,并且我想要给出的提交消息在文件中指定。
$svnExe = "C:\Program Files\TortoiseSVN\bin\svn.exe"
$myFile = "C:\xx\file.txt"
$commitMsg = "C:\xx\msg.txt"
$myFile
已经是版本文件,$commitMsg
不是也不会是版本化文件。
从命令行可以这样工作:
svn commit -F C:\xx\msg.txt C:\xx\file.txt
但我该如何使用 PowerShell 来做到这一点呢?
Svn 在 PowerShell 中的工作方式与在命令提示符中的工作方式相同。如果您使用可执行文件的完整路径定义变量,则需要通过呼叫接线员 https://msdn.microsoft.com/en-us/powershell/reference/3.0/microsoft.powershell.core/about/about_operators (&
),因为否则 PowerShell 会简单地回显该字符串,并对命令行的其余部分感到困惑。
$svn = 'C:\Program Files\TortoiseSVN\bin\svn.exe'
$myFile = 'C:\xx\file.txt'
$commitMsg = 'C:\xx\msg.txt'
& $svn commit -F $commitMsg $myFile
如果将 Svn 目录添加到路径环境变量中,则可以直接调用可执行文件:
$env:PATH += ';C:\Program Files\TortoiseSVN\bin'
...
svn.exe commit -F $commitMsg $myFile
另一种选择是为可执行文件定义别名:
New-Alias -Name svn -Value 'C:\Program Files\TortoiseSVN\bin\svn.exe'
...
svn commit -F $commitMsg $myFile
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)