svn command line tutorial for beginners 2

April 17th, 2007 mysurface Posted in Developer, diff, mv, svn, vimdiff | Hits: 207827 | 16 Comments »

This is the continues tutorial for svn command line tutorial for beginners 1. The previous post covers Introduction of subversion, installation links, how to get help, create svn repository, import files into a new repository and list the files inside a repo.

svn command line tutorial for beginners continues ….

How to checkout files from svn repo?
This is the most critical part of svn and also the most common part of svn command line. A lots of open source development projects provided the way for user to check out their latest code through the internet.

You need to check out in order to commit the changes to svn repo later. Refers back to the previous post, where I import entire directory /home/mysurface/programming to programming_repo. I am going to checkout to the same folder. If you are skeptical of doing this, you may want to backup the directory first.

mv programming programming-bk 

Now checkout to programming, mkdir is not needed, as svn will create the directory for you if it is doesn’t exist.

svn co file:///home/mysurface/repo/programming_repo programming 

co is the shortform of checkout.

Okay, lets just compare both folder with diff and store the result into a file comp.diff

diff programming programming-bk > comp.diff 

Diff will list the folder in common, and also the differences. Check comp.diff, as it tracks the additional folder .svn that only exist in programming/. Again, do NOT modified or delete this folder.

Are you convinced to remove your programming-bk/ ? Make sure you keep the repo safe and you can check out the same data anytime, at any place.

You can even checkout only a specific file or specific folder from your repo. e.g.

svn co file:///home/mysurface/repo/programming_repo/c/curses/matrix.cc

This will only check out a file at current directory.

Single file can’t be checkout like directories, but you can extract them from repository by svn export

 svn export file:///home/mysurface/repo/programming_repo/c/curses/matrix.cc

How to track the changes before commit to repo?
First of all, you track what files had changed,

svn status

It will list files which have changed, with some attributes besides the filename. Common attributes are M, ?, A … M is modified, A is newly added (how to add refers later section), ? indicate the file is added into local directory but not added into repo.

Secondly, you want to track the differences between the previous revision and the working one. Lets assume color.c has changed,

svn diff color.c

I really don’t like svn diff ‘s result. Fortunately, I found a simple bash script what makes vimdiff as the compare tool. The script was written by Erik C. Thauvin, you can get it from here.

I name it as svndiff and place it at /usr/bin, change the mode to executable.

chmod +x /usr/bin/svndiff 

Now, I can simply do this,

svndiff color.c

To close the vimdiff, type :qa

How to commit the changes?
You can commit with -m to place your log message if it is short. But if it is long, I suggest you to make use of your default editor. I am a vim user, therefore I add a line into my ~/.bashrc

EDITOR=vim

Now I can commit with this:

svn ci

ci is the shortform of commit. Write the log message and close save vim :x, I am done. The same way as checkout, you can choose to commit one file or any folder.

How to add or delete file to or from repo?
The file won’t be committed if you don’t add it into repo. Therefore you need to add it manually if you want it to goes into your repo. Let say you wanna add a new file color2.cc

svn add color2.cc

Delete does the same way, if you only delete file at your working directory, it won’t reflects the changes to our repo.

How to check the logs for each revision?
The simplest way is doing just,

svn log

It will list all logs, start from latest revision. That is really irritating! You can limit it to 3 latest revision log by doing this

svn log --limit 3

If you wanna check for specific revision, specified with -r,

svn log -r 3

I find something awkward, let say I have done svn delete at revision 3 (latest), and revision 2 is the changes of the deleted file at revision 3. When I do svn log, by right it should show all 3 logs, but It only shows for revision 1. It means the svn log will only shows the log if the file is exist, bare in mind.

How to update the working directory into the latest revision?

svn update

Update to specific revision?

svn update -r 3

I think thats all for normal use of svn commands, further reading at http://svnbook.red-bean.com/.

[tags]svn tutorial, subversion, svn howto, source version control[/tags]

16 Responses to “svn command line tutorial for beginners 2”

  1. [...] Continue reading next post …. Related Posts svn command line tutorial for beginners 2This is the continues tutorial for svn command line tutorial for beginners 1. The previous post covers Introduction of s… windows user access ssh through puttyPutty is a great ssh client for windows user, it is easy to use and lightweight too. Do you expect to see a tutorial or … Write a functionTo write a function, choose a syntax you prefer, either: function funct-name { commands; } or: funct-name() { c…                              [...]

  2. “ci is the shortform of commit”

    i think it’s more to checkin as in “check in”

  3. mypapit:

    I think so, as svn checkin doesn’t exist, instead svn commit. But checkin or commit, it just the different name but does the same function.

  4. Please try SVNManager!

  5. [...] Refers back to svn command line tutorial for beginners 2, I introduces a bash script that uses svn cat and vimdiff to compare files. This simple script written by Erik C. Thauvin only allows you to compare latest revision source with working source. [...]

  6. Hello,

    nice article, thanks! However you say:
    “You can even checkout only a specific file or specific folder from your repo. e.g. svn co file:///home/mysurface/repo/programming_repo/c/curses/matrix.cc”.
    If i try this at home, i get an svn error. So i consulted the SVN FAQ and found:
    ——
    How do I check out a single file?

    Subversion does not support checkout of a single file, it only supports checkout of directory structures.

    However, you can use ‘svn export’ to export a single file. This will retrieve the file’s contents, it just won’t create a versioned working copy.
    ——

    Why you are able to checkout only a specific file? What’s the trick?

    Greetings,
    andreas

  7. Andreas: You are right, I think I had make some mistakes while writing that. Thanks for raising this up, export will be the only solution to copy out a file from a repo.

  8. Wonderfull beginers tutor!!!!!!!!!!!

  9. started using svn today, and I’m currently giving myself a facepalm for not using it earlier :)
    great tutorial btw

  10. Is there a ‘cc’ command? What does this do?

  11. difference between the trac and svn version
    what is the use of it

  12. use svn diff instead of svndiff(it won’t work)
    good material
    Thank U

  13. Hi I am a new learner of Subversion and want to know how to create groups for repository and create users for these groups and give access.

  14. yellowpages category pet KAMIsSimilar

  15. Hi ,

    i need to creatd svn in a linux machine (by using core svn)
    but i got some problem and i deleted repository directory and created new one. without using the svn switch command, now am getting the

    svn: ‘.’ is not a working copy
    svn: Can’t open file ‘.svn/entries’: No such file or directory

    erorr masg. if use add, commit, adn other command getting the same error. wt to do.

    Thnaks
    PASHA.

  16. Valuable іnformation. Lucky mе I ԁiscoveгeԁ your site unintentіonally, and
    I am ѕtunned why thiѕ coincidenсe did not happened іn аdvanсe!
    I bοοκmaгked it.

Leave a Reply