in reply to Learning How to Use CVS for Personal Perl Coding Practices

Short example of how to start out with subversion (honestly, if you're just starting out I don't see merit in beginning with one of the older version control systems, they're no easier to learn and make your daily life harder).

Let's say your current code is in /home/neversaint/code and you'd like to keep the subversion repository (the backend storage, i.e. database if you will) in /home/neversaint/subversion.

svnadmin create /home/neversaint/subversion
This will create an empty repository for you.
cd /home/neversaint/code svn import . file:////home/neversaint/subversion
This will import your codebase into the repository.
mkdir /home/neversaint/workspace cd /home/neversaint/workspace svn co file:///home/neversaint/subversion
This will create a new copy of your current codebase in /home/neversaint/workspace. From then on, make all changes to these files. Whenever you want to save your files to the repository, do a
svn -m "Commit message" ci

This will update the repository to the state of the workspace.

For further instructions, see the book pointed out by duff and the subversion documentation, execute

svn help
and
svn help <command>
for details on certain commands.
Update:Changed to using real-world paths, after msg's asking for clarification, also fixed a syntax error in the create.

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian W. Kernighan

Replies are listed 'Best First'.
Re^2: Learning How to Use CVS for Personal Perl Coding Practices
by Rhose (Priest) on Nov 03, 2005 at 15:13 UTC
    While there is nothing incorrect with your example, I've followed the suggestion of using trunk, tags, and branches, and have found it to be very helpful. (Use branches for parallel development... like migrating code to a new platform while development continues on the current one. Use tags for "point in time" snapshots.) I use this structure even for repositories for which I'm *sure* I'll never need them. (If, for no better reason, than to always know I need to check out the trunk on any given repo.)

    You set this up before the initial import. Create a directory (let's assume /home/rhose/svn). In this directory, create three more directories -- trunk, tags, and branches. Place all your directories/code in the trunk directory.

    cd /home/rhose mkdir svn cd svn mkdir trunk mkdir tags mkdir branches cd trunk cp /home/rhose/work/project123/* .

    You are now ready to import. (Please note, I'm using the Subversion daemon in this example.)

    svn import /home/rhose/svn svn://myserver/myrepo -m "Initial import"

    You are now free to nuke your import structure, checkout the trunk, and start working. Also, I like to make a temporary copy of the original files until I verify the repo import worked correctly and everything is in there... I've never had a problem, but I tend to play it extra safe. (Please note... once you check out a repo, do NOT mess with the .svn directories -- like Bruce Banner, you'll not like them when they're angry.)

    cd /home/rhose/svn rm -rf * cd /home/rhose/work mv project123 project123.save mkdir project123 cd project123 svn checkout svn://myserver/myrepo/trunk/ . vi mycode.pl svn commit -m "Made change XXX for project YYYY" cd .. rm -rf project123.save

    If you are in a Windows environment, I'd like to second tphyahoo's advice -- TortoiseSVN is wonderful.

      Dear Rhose,
      [snip] svn://myserver/myrepo [snip]
      Where and how do you set/define this server repository? Say if I am only working locally for myself.

      ---
      neversaint and everlastingly indebted.......
        Read chapters 1,2,3,5, and 6 of The SVN Book referenced in the posts above.

        Basically, instead of writing to a local file, you can share your repository (make it available for people on other computers) using a Subversion daemon or Apache. This takes a little bit of effort to set up, but it works well.

        The url for a local repository is file:///path/to/repository

        - caedes

Re^2: Learning How to Use CVS for Personal Perl Coding Practices
by neversaint (Deacon) on Nov 03, 2005 at 16:23 UTC
    Dear tirwhan,
    Let me make myself clear again. Please bear with me. Suppose I have the following directory which contain a file (myperlcode.pl) which I want to store them with SVN.
    ~/MyPerl | |__Project1 | |__ myperlcode.pl Note: ~/ = home/neversaint
    Following your advice what I tried to do is following steps.

    Step 1: Creating a subversion main repository and repository related to Project1
    home/neversaint $ mkdir subversion home/neversaint $ cd subversion home/neversaint/subversion $ svnadmin create Project1
    Listing them:
    home/neversaint/subversion $ cd Project1 home/neversaint/subversion/Project1 $ ls README.txt conf dav db format hooks locks
    Step 2: Attempting to create empty repository
    home/neversaint/subversion $ cd ~/MyPerl/Project1 home/neversaint/MyPerl/Project1 $ svn import . file:///~/subversion/Pr +oject1 ^ | Note: did I get this right? ---------------------|
    Now, at this point I encounter problem with this message:
    svn: Could not use external editor to fetch log message; consider<br> setting the $SVN_EDITOR environment variable or using the --message (-m) or --file (-F) options svn: None of the environment variables SVN_EDITOR, VISUAL or EDITOR is set, and no 'editor-cmd' run-time configuration option was found
    Is there anything wrong with my steps above? Did I misunderstood your advice above? Hope to hear from you again.

    ---
    neversaint and everlastingly indebted.......
      Import (like commit) needs a log message. I'd use the -m switch on the import. (Although you can define the editor and enter the log message using it.)

      svn import . file:///~/subversion -m "Initial import"

        Hi Rhose,

        I tried this:
        svn import . file:///~/subversion/Project1 -m "Initial import"
        But it gave:
        svn: Unrecognized URL scheme 'file:///~/subversion/Project1'


        ---
        neversaint and everlastingly indebted.......