Tuesday, July 24, 2012

SVN Commands

For those who like to use svn from command line, these are the useful commands to remember.
As you use them regularly, you don't need to see this post again.. :D

1) Checkout a project:
    svn checkout url

2) Update and revert:
    -To update local files in a repository:
      svn update filename1, filename2,.
    -To update the entire repository
      svn update

3) revert to the previous version
    svn revert filename1, filename1, ...

4)Difference
   cd folder_name
   diff filename

5)How to commit files:

- Perform an svn diff to check the changes you made-  svn diff
- Then update the file- svn update . There might be conflicts. Then again perform svn diff to check   the conflicts. 

-This diff now shows up the differences between your current file and what's there now in the repository. 
-Check that only the new code you have added is the sum total of the differences. 
svn commit -m "Commit message"


svn diff filename1, filename2, ... , filenamen
svn update 
filename1, filename2, ... , filenamen
svn diff 
filename1, filename2, ... , filenamen
svn commit 
filename1, filename2, ... , filenamen


6)Adding a  new file to the repository:

    svn add filename
    svn commit -m "Commiting the new file that is added" filename



7)Deleting a file from the repository
   svn remove -m "Deleting the file which is not required" filename
 

8)Conflicts and resolving them
-If, when doing an "svn status" of a folder you find any files marked with a C, then it means such    files are in conflict with their corresponding versions in the svn repository.
 

-Doing an "svn update" may indicate files are in conflict as well. If you performed an "svn update" on some files (or on a folder) and one or more came up with the status C then you have a conflict. It means that changes to the same file on the same lines had been committed to the svn repository as what you have been working on. The update could not successfully merge the corresponding lines as it didn't know which lines to keep and which to overwrite: the lines are in conflict.
 

-If you ever encounter a file in conflict and you view it in an editor, you will see that conflicted lines will be marked with ===== and >>>>>. Both the changes you made and the conflicting changes in the repository will be embedded inside such special marks. 
(If you had done an "svn update" on files that turned out to conflict, the action would have created a couple of additional versions of the file: conflict-filename.mine and conflict-filename.. The first is your local version containing the changes you made. The second is the file as it is in the svn repository.)

To resolve conflicts in a file marked with a C
1.    Open up the file that's in conflict in an editor.
2.    Search for all occurrences of >>>> or ===. Each occurrence marks a conflicted section and needs to be resolved.
3.    Deal with marked sections as appropriate: decide which parts you want to keep, which should be removed or how to combine (the best of) both.
4.    Once you've finished editing out the conflicts in the file, you have to set the file's status to resolved for it to be up to date (and updateable with svn):

5.    svn resolved


9)To check the log
    svn log



10) SVN import
If you want to put this project folder into the repository, inside http://svn.abc/other-projects/trunk/ then you would type the following in your x-term:
 

cd my_program
svn import -m "my message" . http://svn.abc.org/other-projects/trunk/my_program



11) Blame
To get the info about which user has committed the code line by line for a particular file

svn blame filename


Happy coding,

Kaustubh



No comments:

Post a Comment