简体   繁体   中英

How to use TortoiseSVN via command line?

I use TortoiseSVN and want to use command line SVN options.

I used the command:

svn checkout [-N] [--ignore-externals] [-r rev] URL PATH

and get the following error:

'svn' is not recognized as an internal or external command

Is it because I need to add some environment variable? Or can't TortoiseSVN be used from the command line?

By default TortoiseSVN always has a GUI (Graphical User Interface) associated with it. But on the installer (of version 1.7 and later) you can select the "command line client tools" option so you can call svn commands (like svn commit and svn update) from the command line.

Here's a screenshot of the "command line client tools" option in the installer, you need to make sure you select it:

如何安装 TortoiseSvn-CommandLineTools

TortoiseSVN has a command-line interface that can be used for TortoiseSVN GUI automation and it's different from the normal Subversion one.

You can find information about the command-line options of TortoiseSVN in the documentation: Appendix D. Automating TortoiseSVN . The main program to work with here is TortoiseProc.exe .

But a note pretty much at the top there already says:

Remember that TortoiseSVN is a GUI client, and this automation guide shows you how to make the TortoiseSVN dialogs appear to collect user input. If you want to write a script which requires no input, you should use the official Subversion command line client instead.

Another option would be that you install the Subversion binaries. Slik SVN is a nice build (and doesn't require a registration like Collabnet). Recent versions of TortoiseSVN also include the command-line client if you choose to install it.

In case you have already installed the TortoiseSVN GUI and wondering how to upgrade to command line tools, here are the steps...

  1. Go to Windows Control Panel → Program and Features (Windows 7+)
  2. Locate TortoiseSVN and click on it.
  3. Select "Change" from the options available.
  4. Refer to this image for further steps.

    TortoiseSVN 命令行启用

  5. After completion of the command line client tools, open a command prompt and type svn help to check the successful install.

To use command support you should follow this steps:

  1. Define Path in Environment Variables:

    • open ' System Properties ';
    • on the tab ' Advanced ' click on the ' Environment Variables ' button
    • in the section ' System variables ' select ' Path ' option and click ' edit '
    • append variable value with the path to TortoiseProc.exe file, for example:

      C:\\Program Files\\TortoiseSVN\\bin

  2. Since you have registered TortoiseProc , you can use it in according to TortoiseSVN documentation .

    Examples:

    TortoiseProc.exe /command:commit /path:"c:\\svn_wc\\file1.txt*c:\\svn_wc\\file2.txt" /logmsg:"test log message" /closeonend:0

    TortoiseProc.exe /command:update /path:"c:\\svn_wc\\" /closeonend:0

    TortoiseProc.exe /command:log /path:"c:\\svn_wc\\file1.txt" /startrev:50 /endrev:60 /closeonend:0

PS To use friendly name like 'svn' instead of 'TortoiseProc', place 'svn.bat' file in the directory of 'TortoiseProc.exe'. There is an example of svn.bat:

TortoiseProc.exe %1 %2 %3

要启用 svn 再次运行 TortoiseSVN 安装程序,请选择“修改”(允许用户更改安装功能的方式)并安装“命令行客户端工具”。

My solution was to use DOSKEY to set up some aliases to for the commands I use the most:

DOSKEY svc=TortoiseProc.exe /command:commit /path:.
DOSKEY svu=TortoiseProc.exe /command:update /path:.
DOSKEY svl=TortoiseProc.exe /command:log /path:.
DOSKEY svd=TortoiseProc.exe /command:diff /path:$*

Google "doskey persist" for tips on how to set up a .cmd file that runs every time you open the command prompt like a .*rc file in Unix.

You can have both TortoiseSVN and the Apache Subversion command line tools installed. I usually install the Apache SVN tools from the VisualSVN download site: https://www.visualsvn.com/downloads/

Once installed, place the Subversion\\bin in your set PATH. Then you will be able to use TortoiseSVN when you want to use the GUI, and you have the proper SVN command line tools to use from the command line.

There is a confusion that is causing a lot of TortoiseSVN users to use the wrong command line tools when they actually were looking for svn.exe command line client.

What should I do or can't TortoiseSVN be used from the command line?

svn.exe

If you want to run Subversion commands from the command prompt, you should run the svn.exe command line client. TortoiseSVN 1.6.x and older versions did not include SVN command-line tools, but modern versions do.

If you want to get SVN command line tools without having to install TortoiseSVN, check the SVN binary distributions page or simply download the latest version from VisualSVN downloads page .

If you have SVN command line tools installed on your system, but still get the error 'svn' is not recognized as an internal or external command , you should check %PATH% environment variable. %PATH% must include the path to SVN tools directory eg C:\\Program Files (x86)\\VisualSVN\\bin .

TortoiseProc.exe

Apart from svn.exe , TortoiseSVN comes with TortoiseProc.exe that can be called from command prompt. In most cases, you do not need to use this tool, because it should be only used for GUI automation. TortoiseProc.exe is not a replacement for SVN command-line client.

As Joey pointed out, TortoiseSVN has a commandline syntax of its own. Unfortunately it is quite ugly, if you are used to svn commands, and it ignores the current working directory, thus it is not very usable - except for scripting.

I have created a little Python program ( tsvn ) which mimics the svn commandline syntax as closely as possible and calls TortoiseSVN accordingly. Thus, the difference between calling the normal commandline tools and calling TortoiseSVN is reduced to a little letter t at the beginning.

My tsvn program is not yet complete but already useful. It can be found in the cheeseshop ( https://pypi.python.org/pypi/tsvn/ )

After some time, I used this workaround...

(at the .bat file)

SET "CHECKOUT=http://yoururl.url";
SET "PATH=your_folder_path"

start "C:\Program Files\TortoiseSVN\bin" svn.exe checkout %CHECKOUT% %PATH%

My fix for getting SVN commands was to copy .exe and .dll files from the TortoiseSVN directory and pasting them into system32 folder.

You could also perform the command from the TortoiseSVN directory and add the path of the working directory to each command. For example:

C:\Program Files\TortoiseSVN\bin> svn st -v C:\checkout

Adding the bin to the path should make it work without duplicating the files, but it didn't work for me.

After selecting "SVN command line tools" it will become like this:

在此处输入图片说明

I had command line tools installed already, but still I was not able to fix this error.

  • I restarted Android Studio, but it did not solve my issue

Then I realized that after installing SVN I had not restarted the PC, and that was the major issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM