Monday, 17 April 2017

SVN Commands and their explanation

1) checkout / co SVN Command
checkout / co command is used to checkout a project and its current files from the svn server.
Usage:
svn checkout http://<servername>/testsvn
or
svn co http://<servername>/testsvn
Example:
·         Now you can download the projects from the server using below command.
svn checkout http://localhost/testsvn or
svn co http://localhost/testsvn
localhost - is the server name or ip in which the svn repository is running.
testsvn - is the project name.

·         Consider that there was a file in the server repository for this project named 'test1.txt'.
The following files will be downloaded from 'test1.txt' using checkout cmd,
- folder named 'testsvn'.
- a file inside the testsvn folder named 'test1.txt'.
- svn folder inside testsvn containing all the repository and revision details of the files.
Result:
From the above cmd, the files inside 'testsvn' were checked out.

2) add SVN Command

add command is used to append a new file in to the server.
Usage:
svn add <filename>
Example:
·         Create a file locally name test2.txt (> test2.txt)
Now you can insert it to the server repo as in the below command.
svn add test2.txt
Output:-----------------------------------------------
A test2.txt
---------------------------------------------------------
·         Then commit after the directory is created.
svn ci -m add
Result:
From the above cmd, the file 'test2.txt' will be added in to the server repository. Dont forget to call svn commit to make the new file commited in to the repo.
3) commit / checkin / ci SVN Command
commit / checkin / ci command is used to upload the changes which you have done in the local server, in to the server repo.
Usage:
svn ci <filename> -m <log message>
or
svn commit <filename> -m <log message>
<filename> - You can either use a file name or folder name or need not use it.
The single file will be uploaded if a name is given or all files with new revision in that folder will be uploaded.
<log message> - Give the message about the changes that are done in the current revision of the file or files.
Example:
·         Now you can upload the changes to the server using below command.
svn ci test.txt -m update
or
svn commit test.txt -m update

Output:-----------------------------------------------
Transmitting file data.
Committed revision 3.
---------------------------------------------------------
Result:
By executing the above cmd, the file 'test.txt' will be updated in the repo and a message with the new version of the file will be derived as output.
4) blame SVN Command
blame command is used to print the information of the file like author, revision and file content.
Usage:
svn blame <filename>
Example:
·         Now you can get the information about the file using below command.
svn blame readme.txt
Output:-----------------------------------------------
1 svntest This is a README file.
---------------------------------------------------------

1 - is the revision information.
svntest - is the author information.
This is a README file. - is the content of the file.
Result:
From the above cmd, the informations of the file 'readme.txt' are printed.
5) copy SVN Command
copy cmd is used to copy a file or directory in a working repository.
Usage:
svn copy <filename> <newfilename>
Example:
·         Now you can duplicate the files or directories using below command.
svn copy test.txt test1.txt
Output:-----------------------------------------------
A test1.txt
---------------------------------------------------------
·         svn ci test1.txt -m add
It shows the name of the new file name
Output:-----------------------------------------------------
A - Adding a new file.
test1.txt. - copied filename.
-----------------------------------------------------------------
Result:
From the above cmd, the file 'test1.txt' is copied into the local repository. Dont forget to call svn commit to add the copied file in to server repo.
6) delete SVN Command
delete command is used to remove a file from the svn server repository.
Usage:
svn delete <filename>
Example:
·         To remove a file from server repo, you should have the same version of the file locally.
svn delete test1.txt
Output:-----------------------------------------------
D test1.txt
D - Deleting a file.
test1.txt. - Deleted filename.
---------------------------------------------------------

·         Then commit after delete.
svn ci -m Delete
Result:
By executing the above cmd, the file 'test1.txt' will be deleted from both the server and local repository.Dont forget to call svn commit to delete a file from the server repo.
7) diff SVN Command
diff command is used to check the difference between the content in the files among the local repo and server repository.
Usage:
svn diff <filename>
filename - is not mandatory. If file is not given, svn will report the diff for all the files and folders starting from the current location.
Else it will check the difference of the given file.
Example:
·         Check the difference between content in the files to the server using the below command.
svn diff test1.txt
Output:--------------------------------------------------------------------------
Difference between the local and server file Example Output:
=================================================
--- test1.txt (revision 3)
+++ test1.txt (working copy)
@@ -1,5 +1,5 @@
-sd
asd
+asd
asd
asd
---------------------------------------------------------------------------------------
Result:
The above cmd shows the difference, that the line 'sd' is removed and 'asd' is added in the local working copy.
8) export SVN Command
export command is used to download a project repository in to the local computer or machine on to the specified folder or directory. The difference between checkout and export is that, export will extract all the files from a revision and does not act as working copy. If you want to have a working copy, always go for svn checkout
Usage:
svn export <url> directoryname
Example:
·         Now you can download the project to a new directory using the below command.
svn export http://localhost/testsvn test2
Output:-----------------------------------------------
A testsvn
A testsvn/test2.txt
Exported revision 8.
---------------------------------------------------------
Result:
By using this cmd, all the files and directories in testsvn were downloaded into the new directory 'test2'.
9) help SVN Command
help command provides the information about the svn commands.
Usage:
svn help <subcommand>
<subcommand> - is not mandatory. If command is not given, it will list all the subversion commands.
Example:
·         Now you can get the help about any svn command.
svn help add
Output:---------------------------------------------------------------------------------
add: Put files and directories under version control, scheduling
them for addition to repository. They will be added in next commit.
usage: add PATH...
Valid options:
--targets ARG : pass contents of file ARG as additional args
-N [--non-recursive] : obsolete; try --depth=files or --depth=immediates
--depth ARG : limit operation by depth ARG ('empty', 'files',
'immediates', or 'infinity')
-q [--quiet] : print nothing, or only summary information
--force : force operation to run
--no-ignore : disregard default and svn:ignore property ignores
--auto-props : enable automatic properties
--no-auto-props : disable automatic properties
--parents : add intermediate parents
Global options:
--username ARG : specify a username ARG
--password ARG : specify a password ARG
--no-auth-cache : do not cache authentication tokens
--non-interactive : do no interactive prompting
--trust-server-cert : accept unknown SSL server certificates without
prompting (but only with '--non-interactive')
--config-dir ARG : read user configuration files from directory ARG
--config-option ARG : set user configuration option in the format:
FILE:SECTION:OPTION=[VALUE]
For example:
servers:global:http-library=serf

--------------------------------------------------------------------------------------------
Result:
From the above cmd, the description and syntax about the svn 'add' cmd is printed.
10) info SVN Command
info command is used to get the information about the file like Filename, Path, Repository Root, Repository UUID, Revision, etc.
Usage:
svn info <filename>
<filename> - is not mandatory. If file is not given, it will get the information about the main project.
Example:
·         Now you can get the information about the files using the following command.
svn info test1.txt

Output:--------------------------------------------------------------------------
Path: test1.txt
Name: test1.txt
URL: http://192.168.0.202/testsvn/test1.txt
Repository Root: http://192.168.0.202/testsvn
Repository UUID: 113dae95-3759-4fb1-9849-1d45abce66ef
Revision: 4
Node Kind: file
Schedule: normal
Last Changed Author: testsvn
Last Changed Rev: 4
Last Changed Date: 2006-01-02 02:50:38 +0530 (Mon, 02 Jan 2006)
Text Last Updated: 2012-12-26 16:35:27 +0530 (Wed, 26 Dec 2012)
Checksum: 364093d03b00f0bfd081c319e1594e7a
---------------------------------------------------------------------------------------
Result:
From the above cmd, the information about the file 'test1.txt' was obtained.
11) import SVN Command
import command is used to upload a project from the local folder into the server repository.
Usage:
svn import path <URL> -m <log message>
Example:
·         Now you can import the files or directories using below command.
svn import /home/test/test2/ http://192.168.0.202/svntest/test1 -m 'initial import'
Output:-----------------------------------------------
/home/test/test2/ - Path of the local folder
Adding svntest
Adding svntest/test2.txt
Adding svntest/test
Adding svntest/test1
Skipped '.svn'
Adding dir
Adding test1.txt
Committed revision 8.
-----------------------------------------------------------------
It copies the file and directories from the local folder into the repository.
Result:
By using the above cmd, all the files and directories in test2 were uploaded into the repository.
12) log SVN Command
log command is used to get the log messages with date, time and author information attached to revisions and the paths that are changed in each revision.
Usage:
svn log <filename>
Example:
·         Now you can get the status of the files or directories using below command.
svn log test2.txt
Output:------------------------------------------------------------------------------------
r1 | svntest | 2006-01-01 03:01:14 +0530 (Sun, 01 Jan 2006) | 1 line
update
r1 - revision information
svntest - author information
2006-01-01 03:01:14 +0530 (Sun, 01 Jan 2006) - date and time
update - log message
-------------------------------------------------------------------------------------------
Result:
From the above cmd, the log message for the given file 'test2.txt' is obtained.
13) lock SVN Command
lock command is used to lock the files in the repository. Remember that no other user can checkin the file until it is unlocked again using the unlock command.
Usage:
svn lock <filename>
Example:
·         Let us see how this cmd works.
svn lock test.txt
Output:-----------------------------------------------
'test.txt' locked by user 'svntest'.
---------------------------------------------------------

·         Use unlock command to unlock the file.
Result:
From the above cmd, the file 'test.txt' was locked in the server repository.
14) list / ls SVN Command
list / ls command is used to list each file and the directory as they exist in the repository.
Usage:
svn list <path>
or
svn ls <path>
Example:
·         Let us see how this cmd works.
svn list http://localhost/testsvn/
or
svn ls http://localhost/testsvn/
Output:-----------------------------------------------
README.txt
INSTALL
examples/
--------------------------------------------------------
Result:
From the above cmd, each file and the directory in 'testsvn' are listed.
15) mkdir SVN Command
mkdir command is used to make / create a directory into the current path of the server and local repository.
Usage:
svn mkdir directoryname
Example:
·         Now you can create a directory to the server using below command.
svn mkdir dir1
Output:-----------------------------------------------
A dir1
A - Adding new directory
dir1 - Directory name
------------------------------------------------------

·         Then commit after the directory is created.
svn ci -m add
Result:
This will create a directory named dir1 in the local machine and in to the server repository under the same path from where the command is executed. Dont forget to call svn commit to make the newly created directory commited in to the repo.
16) remove / rm SVN Command
remove / rm command is used to eliminate a file or directory from a working copy or the repository.
Usage:
svn rm <filename>
or
svn remove <filename>
Example:
·         To delete a file from server repo, you should have the same version of the file locally and commit after delete.
svn remove test1.txt
or
svn rm test1.txt
Output:-----------------------------------------------
D test1.txt
D - Deleting a file.
test1.txt. - Deleted filename.
--------------------------------------------------------

·         Then commit after delete.
svn ci -m Delete
Result:
From the above cmd, the file 'test1.txt' will be eradicated from both the server and local repository.Dont forget to call svn commit to remove the file from the server repo.
17) resolve SVN Command
resolve command is used to resolve the conflicts on working copy of the files. Conflict arises when two or more users attempt to make changes in the same file.
Usage:
svn resolve --accept <path>
--accept : specify automatic conflict resolution source
('mine-full', 'theirs-full')
Example:
·         Look at the example of svn resolve,
Consider that,you have edited the file 'test.php', which was already edited and commited by another user in another revision.
Now if you update the changes into repo, you will receive an error message,
svn update
Output:-----------------------------------------------
Conflict discovered in 'test.php'.
Select: (p) postpone, (df) diff-full, (e) edit,
(mc) mine-conflict, (tc) theirs-conflict,
(s) show all options: p
C test.php
Updated to revision 5.
Summary of conflicts:
Text conflicts: 1
------------------------------------------------------------
It shows that file 'test.php' has conflict.
where,
(e) edit - the file will open to edit
(df) diff-full - shows the diff between the versions.
Now the svn will create three files 'test.php.mine' ,'test.php.r5', 'test.php.r6'.
·         Now you can determine the conflicts of the file using the following command,
more 'test.php'
Output:-----------------------------------------------
afdfsdfsdfsdfsd
svn
<<<<<<< .mine
resolve
=======
Svn Test
>>>>>>> .r5
--------------------------------------------------------

·         Now you can resolve conflicts of the file using the following command,
svn resolve --accept mine-full test.php
It will update your changes to the repository.It doesn't merge with changes done by another user.
or
svn resolve --accept theirs-full test.php
It will update your changes to the repository and merge with the changes done by another user.
Result:
From the above cmd, all the conflicts in the file 'test.php' are replaced.
18) resolved SVN Command
resolved command is used to remove 'conflicts' in the working copy files or directories. Conflict arises when two or more users attempt to make changes in the same file.
Usage:
svn resolved <filename>
Example:
·         Look at the example of svn resolved,
Consider that,you have edited the file 'example.php', whic was already edited and commited by another user in another revision.
Now if you update the changes into repo, you will receive an error message,
svn update
Output:-----------------------------------------------
Conflict discovered in 'example.php'.
Select: (p) postpone, (df) diff-full, (e) edit,
(mc) mine-conflict, (tc) theirs-conflict,
(s) show all options: p
C example.php
Updated to revision 5.
Summary of conflicts:
Text conflicts: 1
-------------------------------------------------------
It shows that file 'example.php' has conflict.
where,
(e) edit - the file will open to edit
(df) diff-full - shows the diff between the versions.
·         Now you can determine the conflicts of the file using the following command,
more 'example.php'
Output:-----------------------------------------------
test
for
<<<<<<< .mine
resolved
=======
Svn Test
>>>>>>> .r5
-------------------------------------------------------

·         Now you can resolve conflicts of the file using the following command,
svn resolved example.php
It will merge the changes done by another user and update in to the repository.

·         Now you can commit the file using the command,
svn commit 'example.php' -m update
Output:-----------------------------------------------
Committed revision 7.
-------------------------------------------------------
Result:
From the above cmd, the conflicts in the file 'test1.txt' will be removed and the file will be ready to commit with our working copy.
19) revert SVN Command
revert command is used to undo all the local changes to a file.
Usage:
svn revert <filename>
Example:
·         Now you can undo the changes of the files using below command.
svn revert test1.txt
Output:-----------------------------------------------
Reverted 'test1.txt'
------------------------------------------------------
Result:
Once this command is executed, your local changes inside the file 'test1.txt' will be lost and svn gives no way to get back those changes inside this file.
20) switch SVN Command
switch command is used to update one branch of working copy to any other different URL.
Usage:
svn switch <URL> path
Example:
·         Now you can update the working copy to new url using the below command.
svn switch http://localhost/testsvn /home/test/mytest

/home/test/mytest - New path to copy the files and directories of working copy.
Now the files and directories of working copy will be moved to new folder mytest
Output:-----------------------------------------------
D test2.txt
C test1
D abc
Updated to revision 7.
--------------------------------------------------------
Result:
By executing the above cmd, your local working copy will be changed to new path '/home/test/mytest' and all the files and directories will be copied from the server repo
21) status / stat / st SVN Command
status / stat / st command is used to display the status of working copy of files and directories.
Usage:
svn status
or
svn stat
or
svn st
Example:
·         Now you can get the status of the files or directories using below command.
svn status test
It shows the status of the directory
Output:-----------------------------------------------
D test
------------------------------------------------------
D - Deleted status.
test - directory name.
Result:
The above cmd will print the status of the directory 'test'.
22) update SVN Command
update command is used to update the local files and synchronize with whatever is in the server.
Usage:
svn update
Example:
·         Always be up to date before editing the file for your changes. To do that use the below command ,
svn update

·         For Example : delete the file from the current local svn folder (ex: test1.txt) and run the command svn update.
This will automatically download and update the file test1.txt.
Result:
The above cmd will update an older version of the files and directories in local working copy to the latest version in the server repo.
23) unlock SVN Command
unlock command is used to unlock the files in the working repository.
Usage:
svn unlock <filename>
Example:
·         Now the file 'test.txt' was locked in the repository,to unlock the file use unlock cmd,
svn unlock test.txt
Output:-----------------------------------------------
'test.txt' is unlocked by the user 'svntest'.
-------------------------------------------------------
Result:
From the above cmd, the file 'test.txt' was unlocked and it can be edited by the user.