Monday, 28 August 2017

Getting started with subversion command-line

The following list contains the svn commands most used by a developer:
  • Checkout
  • Update
  • Status
  • Commit
  • Add
  • Revert 
  • Move
  • Delete
The following paragraphs will show examples of these svn commands using the command line interface (CLI).

svn checkout 

Check out a working copy from a repository. Use the following command for the check out of last revision:

 svn co <path_svn>
or
 svn checkout <path_svn>
Examples:
 svn co https://mysvnrep/svn/myproject/trunk
 svn checkout https://mysvnrep/svn/myproject/trunk

It's possible make the check out with the rename of folder name target:

 svn co <path_svn> <folder_name>
Example:
 svn co https://mysvnrep/svn/myproject/trunk myproject

Finally, you can check out of a precision revision

 svn co -r <revision_number> <path_svn>
Example:
 svn co -r 236 https://mysvnrep/svn/myproject/trunk

svn update

Update your working copy with a revision version.
 svn up [-r<revision>]
or
 svn update [-r<revision>]
Note: -r (alias --revision).
If you want update your working copy with the last revision use (without -r option):
 svn update
or
 svn up

svn status

Display the status of working copy files and directories. Diff between your workspace and code repository.
 svn stat <path>
or
 svn st <path>
or
 svn status <path>
<path> is optional parameter, the default value is current folder ( . ). The command output shows the file list with the status for each file. The following status are the most common:

 'A' Item is scheduled for addition.
 'D' Item is scheduled for deletion.
 'M' Item has been modified.
 '?' Item is not under version control.
 '!' Item is missing (e.g., you moved or deleted it without using svn). This also indicates that a directory is incomplete (a checkout or update was interrupted).
 '~' Item is versioned as one kind of object (file, directory, link), but has been replaced by a different kind of object.

svn commit

Send changes from your working copy to the code repository. After the commit from an user X, the changes are available from other users using the svn update command. For commit all files with status changed (M, A, D, etc...) use:
 svn commit -m "<a comment>"
or
  svn ci -m "<a comment>"
If you want commit only a subset of files:
  svn commit -m "<a comment>" file1 file2 ....
Example:
Status before commit
 svn stat
 M Employ.java
 A myPackage/Person.java
Commit only Person.java
 svn commit -m "added Person.java" myPackage/Person.java
Status after commit
 svn stat
 M Employ.java

svn add

Add a new file (or folder) under source control, use the add command:
  svn add <file>
After that use the commit command for send the changes to code repository.
  svn ci -m "a comment" <file>

svn revert

Undo all locat edits. Yuo can revert all files or folders with status A, M and D.
 svn revert <path>
Examples:
Revert a folder edited
 svn revert myfolder
 Reverted myfolder
Revert a file added
 svn add myfile.txt
 A myfile.txt
 svn revert myfile.txt
 Reverted myfile.txt
 svn status
 ? myfile.txt
If you want to revert a whole directory of files, use the "--depth=infinity" option:
 svn revert --depth=infinity .
 Reverted myfolder
 Reverted myfile.txt

svn move

Move a file or directory.
 svn move <src> <dst>
or
 svn mv <src> <dst>
The <src> and <dst> can be local path or url.
Examples:
Use move command in your working copy
 svn move myfile.txt myfile2.txt
  A myfile2.txt
  D myfile.txt
Use the commit command to update the svn repository
 svn ci -m "move example"
 Committed revision 1233
Use move command with url
 svn move -m "move example 2" https://mysvnrepo/svn/trunk/myfile.txt https://mysvnrepo/svn/trunk/myfile2.txt
 Committed revision 1234

svn delete

Delete an item from a working copy or the repository.
 svn delete <url or path file>
or
 svn del <url or path file>
or
 svn remove <url or path file>
or
 svn rm <url or path file>
Example: to delete a file or a directory from your working copy use the following command:
 svn delete MyFile.txt 
After that, you can see the local status
 svn stat
 D MyFile.txt
If you want delete the file in repository then you must execute the commit
 svn ci -m "Delete MyFile"

No comments:

Post a Comment

Welcome

Hello everybody, Welcome in my blog called "Information technology archive". Obviously the topics will be related to Informatio...