Version Control with SVN - Kunnskapsbasen
Version Control with SVN
Subversion (SVN) is a version control system, useful for situations where multiple people are cooperating on files. It is also good for keeping track of changes and modifications in your work.
Norsk versjon Versjonskontroll med SVN
The following article should help you set up and use an SVN repository by using SSH. After creating the repository, you can use typical graphical software, like SmartSVN, TortoiseVSN, or Eclipse with Subclipse.
Creating an SVN repository
Before using SVN, you need to create a repository. This is where all your projects, files, and folders will be. If you don't already have access to a repository, you can create one on the NTNU servers. This requires a log in, and a more detailed description can be found in the SSH article. Students can connect to login.stud.ntnu.no, employees can connect to login.ansatt.ntnu.no.
To create a repository, use the command svnadmin create <path>.
brukernavn@caracal: /svn$ svnadmin create rep
Using SVN through SSH
Note: All commands running in connection with SVN, have to start with svn.
Checkout
The first thing you have to do is to get the files from the repository. This is done with the checkout command. Remember that you here need a folder, in this case svn, to put your content into. To get the complete path for your folder, use the command pwd.
brukernavn@caracal: /svn$ mkdir svn brukernavn@caracal: /svn$ svn checkout file:///home/homer/br/brukernavn/svn/rep svn/ Checked out revision 0.
Add
To add files, you use the command add. Below is an example of how you add a file under version control.
brukernavn@caracal: /svn/svn$ svn add svn.html A svn.html
Commit
commit is used when you want to upload your local version. When you run this command, the local version of the file (with opdates) will be uploaded to the repository.
brukernavn@caracal: /svn/svn$ svn commit svn.html Adding svn.html Transmitting file data . Committed revision 1.
When you run this command, an editor will appear. The standard editor here is pico. Here you enter a short comment about the changes you've made, what and why. To change the standard editor, use the command:
brukernavn@caracal: /svn/svn$ EDITOR=vim; export $EDITOR; echo $EDITOR vim
Update
update is used to download the latest version of a file or folder.
brukernavn@caracal: /svn/svn$ svn update svn.html At revision 1.
Remove
remove is used to remove a file or folder from the version control, and thereby also the repository.
brukernavn@caracal: /svn/svn$ svn remove svn.html D svn.html
Status
status shows which status a file or folder has. Here you can see if a file has been added, is in a conflict or if it's being handled by version control at all.
brukernavn@caracal: /svn/svn$ svn status svn.html R svn.html
Diff
diff shows the difference between tow files or folders. When you run this command, all differences between the who files or folders will show, both locally and in the repository.
- + extra local copy
- - extra copy in repository
brukernavn@caracal: /svn/svn$ svn diff svn.html Index: svn.html =================================================================== --- svn.html (revision 3) +++ svn.html (working copy) @@ -198,4 +198,14 @@ ...
Revert
revert is used to go back to an earlier version of a file or folder. This only happens locally, and will remove most changes.
brukernavn@caracal: /svn/svn$ svn revert svn.html Reverted 'svn.html'
Help
help can be used before all commands to get details or help on how to use them.
brukernavn@caracal: /svn/svn$ svn help add add: Put files and directories under version control, scheduling them for addition to repository. They will be added in next commit. usage: add PATH...
Continued
If you need more information about SVN, you can type the command man svn or svn help in SSH. The website svn-book also have some valuable info.
Checkout to your own computer
After the SVN repository is created via SSH you may want to download a copy to your personal computer. This makes it possible to work with your own programs and environment while still having access to the repository files.
Finding the full path name
While you are connected to the external server via SSH, navigate to the folder where you want the repository to be located.
username@caracal: /svn$ svnadmin create repository_name username@caracal: /svn$ cd repository_name
Then you can find the full path name using the "pwd" command:
username@caracal: /svn/repository_name$ pwd /home/shomeb/b/username/svn/repository_name
The output from the "pwd" command is the full path name to your repository.
Mac and Linux
Create a folder where you want the local copy to be downloaded to, then navigate to the created folder using your terminal.
my_name$ cd local_folder
You can then perform a checkout which will download the repository to your local folder using the following command:
:local_folder my_name$ svn checkout svn+ssh://ntnu-username@login.stud.ntnu.no/home/shomeb/b/username/svn/repository_name
Replace the text after "login.stud.ntnu.no" with the path name you found in the previous step. Note that "login.stud.ntnu.no" can be replaced with different server addresses.
Windows
For Windows the full path name should be the same, but checkout cannot be run from the in-built command line. Instead you need to install an SVN client (ex. toroiseSVN).
About version control
Some of the point about version control is that multiple people can edit the same files at the same time. SVN enables us to constantly have a good overview of the entire project. If someone edits a file and uploads it, everyone else can update their version of the file to contain the same information. This makes it easier to avoid overwriting eachother's changes. SVN is very recomended to use on common prodject spaces, and you can find more information about creating these spaces at Enkel samhandling.
In addition to keeping track of changes, version control also keep track of earlier versions of all files. If a problem occurs with a file or folder, you can easily go back to an older version.
Relevant links
- See Wikipedia's article about Subversion (SVN)
Contact
Students can contact Orakeltjenesten to get help with the setup of an SVN repository. Employees can contact their local IT support.