May 4 2010

More SVN tips

Flag a file to be ignored by SVN updates/commits

Good tip here

Use svn and git together

See this (though when they say “/opt/local/libexex/git-core” they have a typo and they mean “/opt/local/libexec/git-core”) and this


Mar 29 2010

Simple svn usage

I just started really using svn. This is the way I would’ve liked it explained to me:

An svn repository is like a regular server, except it keeps track of changes to the files you upload in a neat way (and much more but that’s the main idea). Once you have the repository set up (I have Dreamhost and they make it really easy) you can start uploading anything that you want to keep track of, usually a project of some sort.

You commit changes to the repository (modifying, adding, deleting stuff) in svn. svn calls every change that you commit a revision and the default revision is zero when the repo is first created and empty. I’ve only used repos as a place to upload and keep track of my projects; that’s the simplest way to use it.

Let’s say I created my repo at svn.noemartinez.com/myproject. There’s many protocols you can access your repo through, depending on the setup. Dreamhost lets you setup http/https (using “http://” prefix) users when you create the repo, but you can also access it using your existing ssh users (using “svn+ssh” prefix) for the domain.

One thing is, when you try to use the raw URLs, either http://svn.noemartinez.com/myproject or svn+ssh://svn.noemartinez.com/myproject, svn will take the username that you’re logged in with at the computer you’re using to access the repo, which is sometimes (usually) not the same as the http/ssh user you want to access the repo through. To use a the right user, the –username argument works for http (as the man page for svn says), for example

svn list --username [user] http://svn.noemartinez.com/myproject

but for ssh you have to use the syntax:

svn list svn+ssh://[user]@svn.noemartinez.com/myproject

In any case, the main svn commands you end up using for a simple project, in my opinion, are import, export, checkout, update and commit.

Usually, at the beginning you have an empty repo set up, and a bunch of files locally in a computer that you want to end up managing with svn (say, a folder called project). Initially, they are “unversioned” (meaning the svn repo is not linked to them and svn doesn’t know they’re in your computer). To import unversioned files to the repo at first, you use the import command, like this:

svn import --username [user] [path to project] http://svn.noemartinez.com/myproject

From then onwards, the folder project will be saved on the repository. However, the original project folder on the computer is still not a working copy (SVN still isn’t linked to it). To begin editing a working copy whose changes will be kept track of, you have to checkout the project from SVN now that it’s there. Use the command like this:

svn checkout --username [user] http://svn.noemartinez.com/myproject my-working-copy

So now you have a copy of the project in the folder my-working-copy that’s linked to the repo. You can go ahead and modify your project as much as you want. After some changes, or when you have something new working, for example, you’ll want to start updating the project on the repo. To do this, go to the folder you want to commit (usually the top folder, my-working-copy in this case), and use the commit command:

svn commit -m "I got a new feature working"

This submits all changes to the repository, creating a new revision of the project, and attaching the message “I got a new feature working” to this revision.

If you want to make sure your project is updated to the latest version (with all the changes all other users may have commited), use the update command:

svn update

Finally, if you ever want to have a copy of the project without all the svn information, that is, to have an unversioned copy again, use the export command, either using the repo directly, or using your working copy:

svn export --username [user] http://svn.noemartinez.com/myproject my-exported-project

or

svn export --username [user] my-working-copy my-exported-project