如何在powershell中使用SVN提交 [英] How to use SVN-commit in powershell
问题描述
我想在我的 PowerShell 脚本中使用 SVN 命令.
I would like to use SVN commands in my PowerShell script.
我知道我需要将 SVN 可执行文件声明为变量,但之后我想提交一个已声明为变量的文件,并且我想提供的提交消息在文件中指定.
I know I need to declare the SVN executable as a variable, but afterwards I want to commit a file which I have declared as a variable and the commit message I would like to give is specified in a file.
$svnExe = "C:\Program Files\TortoiseSVN\bin\svn.exe"
$myFile = "C:\xx\file.txt"
$commitMsg = "C:\xx\msg.txt"
$myFile
已经是版本文件,$commitMsg
不是,也不会是版本文件.
$myFile
is already a versioned file, $commitMsg
is not and will also not be a versioned file.
从命令行这有效:
svn commit -F C:\xx\msg.txt C:\xx\file.txt
但是我将如何使用 PowerShell 执行此操作?
But how would I do this using PowerShell?
推荐答案
Svn 在 PowerShell 中的工作方式与在命令提示符中的工作方式相同.如果您使用可执行文件的完整路径定义变量,则需要通过 调用运算符 (&
),否则 PowerShell 只会简单地回显字符串,并对命令行的其余部分感到困惑.
Svn works the same way in PowerShell as it does in a Command Prompt. If you define a variable with the full path to the executable you need to run it via the call operator (&
), though, because otherwise PowerShell would simply echo the string and be confused about the rest of the commandline.
$svn = 'C:\Program Files\TortoiseSVN\bin\svn.exe'
$myFile = 'C:\xx\file.txt'
$commitMsg = 'C:\xx\msg.txt'
& $svn commit -F $commitMsg $myFile
如果将 Svn 目录添加到路径环境变量中,则可以直接调用可执行文件:
If you add the Svn directory to your path environment variable you can just invoke the executable directly:
$env:PATH += ';C:\Program Files\TortoiseSVN\bin'
...
svn.exe commit -F $commitMsg $myFile
另一种选择是为可执行文件定义别名:
Another option would be to define an alias for the executable:
New-Alias -Name svn -Value 'C:\Program Files\TortoiseSVN\bin\svn.exe'
...
svn commit -F $commitMsg $myFile
这篇关于如何在powershell中使用SVN提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!