Version Control
From SEWiki
Contents |
Overview
There's a Subversion repository that everyone can use in Dr. Coppit's home directory. Within the department, you can access it using the URL
file:///home/f85/coppit/svnroot.
Remotely, the best way to access it is with the Subversion-over-ssh protocol
svn+ssh://<USERNAME>@<MACHINE>.cs.wm.edu/home/f85/coppit/svnroot.
If you are in a directory that was checked out using Subversion, you don't need to specify the repository for any svn commands---it will use the original repository by default.
From the command line you can look at the repository using the list command:
svn list svn+ssh://<USERNAME>@<MACHINE>.cs.wm.edu/home/f85/coppit/svnroot
You can also view the repository online using our viewcvs interface.
You will see that we have several directories for papers, software, etc. There's also a "people" area where you can store things you are working on. If you browse around, you will see the general structure is of subdirectories, with trunk, tags, and branches at the leaves. The idea is that we won't branch or tag the inner directories, whereas the files for the projects themselves might be.
When using ssh access, you may get tired of typing your password. If so, and you trust the computer you're working from, you can set up SSH to use a private and public key pair for password-less logins. There are a number of guides on the web for how to do this. Here is one, and another, and another. If you use Windows, you might be interested in PuTTY and WinSCP.
Subversion Notes
There's a very good online book Version Control with Subversion. For help with any command, just run svn help <command>.
Checkout
Get an editable copy of the code using svn checkout. For example, the following command will get a copy of the trunk (main) version of a paper:
svn checkout svn+ssh://<USERNAME>@<MACHINE>.cs.wm.edu/home/f85/coppit/svnroot/papers/testing_with_assertions/trunk testing_with_assertions
The last argument specifies the local directory name.
Move/Rename
Most of the svn commands are intuitive with respect to the source and destination. For example, you can move something in the repository without actually doing a checkout:
svn move svn+ssh://<USERNAME>@<MACHINE>.cs.wm.edu/home/f85/coppit/svnroot/testing_with_assertions svn+ssh://<USERNAME>@<MACHINE>.cs.wm.edu/home/f85/coppit/svnroot/papers/testing_with_assertions
Update and Commit
Update your copy with changes made by others using svn update. (It's always a good idea to update and compile/test before doing a checkin, since you may need to resolve conflicting edits or nonconflicting but incompatible edits.) You can also update your local copy with changes made in a different branch or a previous version (to revert a change).
Commit your changes using svn commit. Before you check in your changes, you should run svn diff to remind yourself the changes you've made, and svn status in case you forgot to add some files using svn add.
Add and Import
To add a file, just use svn add. Watch out when adding a binary file that subversion correctly recognizes it and displays "(bin)" as the add happens. Details are below.
To import a bunch of stuff into Subversion, use the svn import command. For example, let's say you want to import a paper you've been working on:
cd testing_with_assertions svn mkdir svn+ssh://<USERNAME>@<MACHINE>.cs.wm.edu/home/f85/coppit/svnroot/papers/testing_with_assertions svn mkdir svn+ssh://<USERNAME>@<MACHINE>.cs.wm.edu/home/f85/coppit/svnroot/papers/testing_with_assertions/trunk svn mkdir svn+ssh://<USERNAME>@<MACHINE>.cs.wm.edu/home/f85/coppit/svnroot/papers/testing_with_assertions/branches svn mkdir svn+ssh://<USERNAME>@<MACHINE>.cs.wm.edu/home/f85/coppit/svnroot/papers/testing_with_assertions/tags svn import -m "initial import" svn+ssh://<USERNAME>@<MACHINE>.cs.wm.edu/home/f85/coppit/svnroot/papers/testing_with_assertions/trunk
In this example, "initial import" is the log message. papers/testing_with_assertions is the location in the repository for the module, with trunk, branches, and tags for later. Feel free to create your own personal Subversion space under the people subdirectory using your userid.
WARNING: This will import all files in the subdirectories from the current directory. You should make sure to delete any intermediate files that don't need to be under version control. Watch out when adding or importing files that they are correctly identified as binary or not. See below for details.
Tagging and Branching
Later on, when you reach a milestone, such as submitting the paper, you can make a tag. Tags and branches are easy in Subversion--they're just copies. Here's an example where we tag the trunk, then add the pdf to the tagged version:
svn copy -m "Tagging the submitted version" svn+ssh://coppit@<MACHINE>.cs.wm.edu/home/f85/coppit/svnroot/papers/software_plans_model/trunk svn+ssh://coppit@<MACHINE>.cs.wm.edu/home/f85/coppit/svnroot/papers/software_plans_model/tags/submitted svn switch svn+ssh://coppit@<MACHINE>.cs.wm.edu/home/f85/coppit/svnroot/papers/software_plans_model/tags/submitted svn add output/software_plans_model.pdf svn switch svn+ssh://coppit@<MACHINE>.cs.wm.edu/home/f85/coppit/svnroot/papers/software_plans_model/trunk
Web Access
Binary Files
A binary file that is treated as ASCII will be corrupted when the newlines are converted according to operating system. The best way to prevent this is to update your svn configuration so that it auto-detects subversion properties based on file extensions. To do this, edit ~/.subversion/config:
- Uncomment the [miscellany] heading* Uncomment enable-auto-props = yes
- Add an [auto-props] section. Here's an example.
To fix a broken import:
- Check out the project
- Run svn propdel svn:eol-style <file> to remove the line conversion property.
- Copy the correct file on top of the one in the checked-out project, replacing the broken one.
- Optionally, run svn propset svn:mime-type application/pdf <file> on the file. In this example we're fixing a PDF file, but use whatever mime-type is in your .subversion/config file.
- Commit your changes.
Ignore Files
If you have directories like "bin" and "lib" that have files that should not be under version control, svn status will show them with question marks. To fix this annoyance (which can obscure new files that need to be added to version control), run svn propedit svn:ignore in the parent directory, and add the directories and files to ignore on separate lines. Patterns like "*.o" also work.
Repository Moved
The repository has been moved from /scratch/coppit/svnroot on the machine th101c-1 to the NFS location ~coppit/svnroot. All existing checkouts need to be moved over using the command:
svn switch --relocate OLD_URL NEW_URL
I've created a script to help with this: switch_all.pl. Just run
switch_all.pl ~
To search for all subversion checkouts starting in your home directory, then convert them to the new repository location.
Other Tips
If you are comparing two checked-out directories, you can specify the --exclude=.svn flag to GNU diff to cause it to skip Subversion's directories. On my account, I've aliased diff to diff --exclude=.svn. See your shell's documentation for how to do this. In bash you put alias diff='diff --exclude=.svn' in your .bashrc.
