Hints for Using SVN to collaborate on school projects
This is a "how to" document for using a graphical user interface with SVN. Graphical user interfaces include
- RabbitVCS for linux
- RapidSVN for Mac
- TortoiseSVN for Windows
Help improve this document by adding SVN command line commands for examples.
Contents
SVN Basics
Directory Structure
|-- Team_Repository_Account +--branches | +-- member-id1 <-- this is a team member's home within branches | +-- Task1 | +-- Task2 | +-- member-id2 <-- this is a team member's home within branches | +-- Task1 | +-- Task2 | +-- Task3 | +-- member-id3 <-- this is a team member's home within branches | +-- Task1 +--tags | +-- R0.1 | +-- R0.11 | +-- R0.2 | +-- R0.21 | +-- ... | +-- R0.5 | +-- ... | +-- R1.0 | +-- R1.1 | +-- R1.2 | +-- R1.21 +--trunk
branches
- branches is the common directory for all team members' workspaces.
- Each team member should create their own home directory or workspace (member-id1, member-id2,...) for their own development tasks within branches.
- Each team member should divide their workspace into several sub-directories (workspaces) during the development of the project. These workspaces(Task1, Task2, ...) are usually copies of the trunk to be worked on.
- These sub-directories(Task1, Task2,...) are called branches of trunk. When the word branch is used as a verb, it means copying the whole trunk into a sub-directory, either in branches or tags.
tags
- tags is the directory that holds copies of successful stages of trunk throughout development. (Also called as Milestones)
- tags are never modified or edited. You may branch a directory of tag into branches under a workspace and then modify the branch and apply the changes back to trunk, but you should never change the contents of a tag
- The action of branching the trunk into tags is often referred to as a release.
- We use the tags directory to submit the work for marking. Your instructor will specify the requirements of a release.
- A release is usually tagged by a version number like: R0.1, Prj0.2, As1_1.0
- When a release is due, your instructor will always mark the latest version of that release.
- If R0.3 is due, and R0.3, R0.31, R0.32 are present in tags, then your instructor will mark R0.32
trunk
- trunk is the directory that holds the project in its current stage, complied and run-able
- trunk should never hold non-compiled code. Usually trunk is an exact copy (or better than) the latest version in tags.
- If only one project is within the repository, then trunk has no project level sub-directory and is the root of the project. If more than one project is within the repository, trunk is divided into several aub-directories for each project to be version-controlled.
- In this case tags should also be divided into exactly the same project sub-directories as trunk
Basic Actions
A few important facts and terminology to help clarify the basic actions:
- One responsibility of a code repository is to keep track of all of the modifications done to a project by its team members.
- In other words, in a project that is handled by a code repository (version-controlled or in short versioned), you can track any changes during the project's development life; such as, who modified/added/deleted what and when. You can undo work or rollback the work to any stage of the development and much more.
- SVN is a client/server repository;
- The code is kept on a server and those members who have access can copy the whole or parts of the project to their local machines, work on the whole or parts and then apply their changes back to the server. Because of this, one member may be unaware of the changes made by another member, unless the other has applied the changes to the server.
- Merging the modifications of different members into the repository is another responsibility.
- A Version-controlled or versioned file is a file that is handled and tracked by a repository
checkout
To checkout is to copy the code from a repository server to a versioned directory on the client, so that you can start working on the code.
branch
To branch is to copy a directory (like trunk) into another directory on the repository server.
- Note that after branching the code is copied on the repository itself and not to the local(client) machine. To work on the branched (copied) code, you must checkout the directory after the branching.
add
To add is to flag a non-versioned file or directory to be added to the repository server at next commit
commit
To commit is to apply (that is, to copy) your modifications and additions to the repository server.
merge
To "merge" is to merge back a branched directory, back to the original directory; that is, to apply the modifications and additions to the branched directory.
- merge is the opposite of branch.
export
To export is to copy the whole or part of a repository to a non-versioned directory on the client machine
- You export when you want either to package the project, to make it ready for production, or to copy a piece of work from one repository to another repository.
import
To import is to copy a non-versioned work (directory) to a repository server.
- note that in this case the imported code is on the server and is still NOT versioned on the client machine; to start working on an imported directory, you should first checkout the directory from the repository to the client machine.
Starting the Project On SVN
There are two ways to initiate a project on SVN:
- To start the project from zero
- We do this when we create an empty project and start to write the code from scratch
- To start the project by continuing existing work
- We do this when someone else has started the project (that is, the professor, other team-members, etc.) and we want to copy the work into our own repository and continue that work.
Start the Project from zero
To start from zero, create the initial code of your project in trunk, add the code, and commit it. These are the steps:
- checkout the project repository in a new directory on your computer;
- Create a new directory on your local computer, right click on the directory, and then click on SVN Checkout
- In URL of the repository type your repository path (svn://zenit.senecac.on.ca/....)
- click on ok
- If the basic directories (trunk, tags, branches) don't exist, create them and add them by right clicking on them and selecting ...SVN/add.
- In trunk, create your project, compile it, and run it. (This could be as simple as few empty files or a Hello world application).
- Right click on the trunk, select ....SVN/add, and select all of the files to be added to the repository.
- Add only those files that you want to track for modification. "Only the source and project files need to be version-controlled". Binary and executable files are usually not added to the repository. Add them only if you have a reason for doing so.
- Right click on trunk and select SVN Commit to commit your work to the repository server.
Start the project by continuing an existing work
To continue an existing work, you should have a non-versioned copy of the initial code for your project. You should copy this code into the trunk, add and commitit. These are the steps:
- Copy the initial code into the trunk of your repository
- If the code is available in another repository (say RepoSrc), export from RepoSrc into trunk of your repository (say RepoDest)
- update RepoSrc to make sure that it is in sync with the server.
- Right click on the directory with the initial code in RepoSrc and select "...SVN/export".
- Select the trunk of RepoDest and click OK
- This will create a "non-version-controlled" copy of the initial code in RepoDest/trunk
- If the code is available in another repository (say RepoSrc), export from RepoSrc into trunk of your repository (say RepoDest)
- Do any modification needed to make the initial code ready for work
- Right click on RepoDest/trunk and select Add. Then choose the files that you want to be "versioned"
- Finally, Commit the trunk to copy the files to the SVN server.
Preparing Branches/workspace for development
For this you should create a home direcotry for your development in branches using your seneca-id. Then your should branch the trunk into the proper workspace in your home directory in branches. Finally you should update, so the new workspace is added to your copy of the repository on your machine. Here is how:
- Create a directory with your seneca-id in branches and add it to the repository and then commit branches to update the repository server.
- Right click on the trunk and select ...SVN/"Branch/Tag" to create a branch for your next task
- By doing this you will create your first workspace to start implementation in the project. Fore next step, choose a relevant name for the task assigned to you, for example if your project is writing a text editor an your next task is to implement "Copy And Past" feature, then the proper name would something like: "CopyPaste"
- In "To URL" type or select your home dir in the branches dir, then add "/CopyPaste" to it: (svn://RepoUrlAndPath/branches/yourSenecaid/CopyPaste")
- Select HEAD revision or a specific revision if necessary (mostly head revision applies in our case)
- Add a proper message for others to know what you have done
- Click on OK
- This copies the trunk into a branch so you can start your implementation, but note that this action is done on server and your local copy of repository still remains the same.
- Right click on branches and click SVN update, this will bring the new branch to your machine.
working on your branch/workspace
- You can now start implementing your assigned tasks.
- Unlike trunk, since this is YOUR workspace you can leave it an any stage you like. don't forget to comment every and each of your commits so later you know which commit belongs to what and also helps your professor to mark your.
- If you do not comment a COMMIT, it means it is minor and does not need to be marked
- You can work form home, commit your work( make sure you add comment to your commit) and them come to school checkout your code work and commit and continue later.
- Make sure if you are working on a public computer, you delete the your work from local computer, after you committed it to the repository.
- It is your responsibility to keep your code safe
- If you have any problem with your code, and need help, contact your professor, send the path of your workspace. If needed, he can checkout your code see what is wrong with it and leave comments on it and commit it. Afterwards, all you need to do is update your repo and read the comments and corrected code.
Merging your work back to trunk
After you have done your work in your workspace and your work is compiling and ready to go, to merge your work back to trunk:
- Right click on trunk or trunk/prj, depending on what you branched into branches
- Select "...SVN/Merge" and select "reintegrate a branch" and click on next.
- Make sure "From URL" is the branch you want to merge and click on next.
- click on "test merge" to see if merge is done successfully.
- click on "merge" to merge the branch back to trunk
- now update the trunk to have the possible changes applied.
- if there is any conflict click on "...SVN/edit conflicts" and fix the conflict, save and click on conflict resolved"
- check the trunk status in your team page on wiki
- If the trunk status is "committed" then change it to "being commited by your_name"
- If the trunk status is "being committed by member_name", wait for the commit to complete and to to previous step.
- commit the trunk and when done, update the truck status to "commited by your_name"
- if this commit was worth recording, branch it in tags directory under a new release.
If you are having the "branch/project must be ancestrally related to trunk/project" error, try going into your trunk and right click > merge one file at a time. Make sure to click the "show log" button in the merge wizard to get the latest revision for the merge added for you.