Yinghui Wang wang382@mcmaster.ca 1
What is subversion Subversion is the tool for controlling the versions of your files. To retrieve a specific version of files To synchronize the modification made by multiple developers to the same files Keep a record of development process 2
Example Suppose you are working on a project alone: Rollback to every copy that you submit to the repository. Suddenly you realized that after weeks of work and after many modifications, the project works not as good as before. Svn can allow you to roll back to a previous version of your project. Suppose you are working on a project as a team member: What if there are conflicts on the same files from different members. Who made THAT change in the file? 3
Where to Get Windows: TortoiseSvn (http://tortoisesvn.tigris.org) - - - integrated with window explorer. Linux or Mac: sudo apt- get install subversion subversion- tools or make and make install the total install package to install. Login into mills, or moore to use it directly. 4
Some terminologies Repository - - - a directory containing the master copy of the project files as well as the changes made to these files. Working directory - - - a directory owned by a developer where she/he edits the project files. Check out - - - retrieve a set of files from repository to working directory. Commit (check in)- - - place the changes made to the files in the working directory into repository. Import - - - add an entire directory tree of files into the repository. The FIRST time when move project files into the empty repository. Update - - - merge the latest changes in the repository into the working copy files. 5
Subversion servers Subversion has two network server options: Apache/WebDAV - - - https:// format. svnserve - - - svn:// format. If you want to create a repository by yourself for your group and make the repository available through network. If you just need to access to your repository locally (by yourself), you do not need a subversion server. 6
Repository URL Schemes http:// or https:// - - - - - when the repository is hosted by a Apache/webDAV server svn://server_name/path/to/repository - - - when the repository is hosted by a svnserve server. file://localhost/path/to/repository - - - when repository and the client are on the same machine or file:///path/to/repository if localhost is omitted. (note: on Windows, if the repository on a different drive, z: for example, the URL would be: file:///z:/path/ to/repository, still use slash rather than back slash) 7
Work Cycle svn import ~/myassignment1/ https://websvn.mcmaster.ca/ cs3c03-4co3/groupn/assign1 - m initial import this example will import files and directories under ~/ myassignment1 into the repository svn co checkout https://websvn.mcmaster.ca/cs3c03-4co3/groupn/ assign1 ~/Groupworkassignment1 This will checkout a copy of latest revision files form the repository and save the working copy in ~/ Groupworkassignment1 svn checkout https://websvn.mcmaster.ca/4co3/groupn/assign1 - r 3 will check out the revision 3 of the files under assign1 directory from the repository and save the working copy to local. This command will create the assign1 directory ~/myassignment1/ can not be used as ~/Groupworkassignment1 svn update up [- r] path, if have checked out for a while. Without path, all local files and directories will be updated to the newest version in repository. svn up r 4 mywork.txt will update mywork.txt in respository back to version 4. Use some option commands provided by svn update when conflict occurs. such as mc or tc 8
svn update (mc) mine- conflict - accept my version for all conflicts (tc) theirs- conflict - accept their version for all conflicts (mf) mine- full - accept my version of entire file (even non- conflicts) (tf) theirs- full - accept their version of entire file 9
Work Cycle svn add delete modify ~/ Groupworkassignment1/1.txt svn delete(del, remove, rm) path m delete mywork svn copy file_name new_file_name (cp) svn move file- name new- file_name svn update svn commit ~/Groupworkassignment1/2.txt m this is my 1.txt You must provide an message even it is empty. Eeeeeehh.. Why my commit fail?? Update it again. You might see conflict. svn resolve - accept= arg 1.txt or svn revert 1.txt Throw away your own changes and start you edit again Modify the conflict to what you think is right. Give remarks. svn resolved 1.txt will remove the conflicted state on the working copy. Commit it again. svn help READ THE DOCUMENT. 10
Import with TortoiseSVN Right click the folder containing the prototype project and then select import. 11
Import with TortoiseSVN Provide the repository URL, and specify a log message 12
Import with TortoiseSVN 13
SVN STATUS http://svnbook.red- bean.com/en/1.0/re26.html? item in not under svn version control, D Delete, A Add! file missing, M Modified, L Locked; C- Conflict with updates received from the repository. 14
15
Create repository svnadmin create repso_dir example: svnadmin create ~/svnrp - - - This example will create a directory svnrp under home directory. svnrp contains a subversion repository and a group of other directories and files which help to manage the subversion repository. (note: the repso_dir has to be local) Change the permission bits so that: The Apache server can read and write to the directory if apache server is used to host the repository. Secure enough (700) if you will run your own svnserve server, or if you want to use the repository locally. Note: you only need to do this step if you want to create your own repository. Most of the time, Derek takes care of this step for you. 16
Other svn commands svn log [ r rev#[:rev#]] - - - to view the log file. examples:svn log svn log r 8 svn log r 3:8 or svn log r 8:3 svn list url or svn ls url - - - to view the files and directory names in the repository. svn cat [- r rev#] filename - - - to view the file contents of a specific version. svn checkout r rev# - - - to check out a specific revision svn cleanup - - - run leftover logs, finished uncompleted jobs and remove locks if the subversion processes were interrupted. 17
Other svn commands svn blame item - - - show revision numbers, authours for each line of contents of a specified files or URLs svn export - - - export a clean directory tree. Files not under version control will not be copied. Example: svn export [-r 3] https://websvn.mcmaster.ca/ robert/trunk ~/temp svn export trunk ~/temp1 svn mkdir - - - make a new directory Example: svn mkdir trunk/newdir svn mkdir https://../trunk/proj/newdir 18
svnserve Server to roll your own repository on network or for a group Start server Start server as a daemon: svnserve d Start server as a daemon and specify a repository path: svnserve d r path/to/repository Note: If r option is used, the svn URL must use the short format. Example: on birkhoff, if run: svnserve d r ~/ mysvnrp and If a project is under ~/mysvnrp/proj then the URL for the project would be: svn://birkhoff/proj Start server to listen to a port other than the default port (3690): svnserve d - - listen- port=7654 then the URL would be svn://birkhoff:7654/.. Edit conf/svnserve.conf, which is under the repository directory 19
Typical svnserve.conf [general] anon-access= none to auth-access=write password-db=passwd realm= Robert s repository # must begin with the first column #unauthorized people. none for no right #read and write. read for viewing the #content, for checking out. write for #deleting, for checking #this is the normal case # specify the file passwd, which is under the #same directory, as the file containing authorized #users names and their passwords. # not essential 20
Sample password- db file for svnserve.conf [users] john=abcd123 mark=234qwe jen=plhgt 21
PracKce - - - - create your own repository for prackce ssh birkhoff - - - - - logon to birkhoff where svnadmin is avalable. Your CAS login name and password are required. cd ~ - - - - - make sure you are under your home directory mkdir svnrepo - - - - - - - - - make a directory under your home directory svnadmin create svnrepo/ - - - create a repository ls la svnrepo/ - - - - will see a lot of system file are there. 22
PracKce- - - create a inikal project mkdir svninit - - - create an directory for initial project cd svninit - - mkdir trunk mkdir branches mkdir tags cd trunk cp /u0/staff/robert/unixtutorial/ver1.txt./ try.txt - - - a lazy way to create your initial project. 23
The content of try.txt the first line--remain the same the second line-- will change it the third line-- will change it the forth line--remain the same the fifth line--will change it the sixth line--will change and add a new line below the seventh line---remain the same the eighth line --will be deleted the ninth line --will be deleted the tenth line--remain the same then add some new lines. 24
PracKce- - - import the inikal project into repository cd ~ - - - - go back to your home directory pwd - - - - - show what is the absolute path of your home directory svn import ~/svninit/ file:///the_pwd_result/ svnrepo/ - m my initial project svn list file:///the_pwd_result/svnrepo/ - - - - check what is in the repository. svn list file:///the_pwd_result/svnrepo/trunk/ - - - check what is under the trunk directory in repository. 25
PracKce- - - check out working copys cd ~ - - - - go back to your home directory mkdir svnworking1 - - - make a working directory for developer 1 mkdir svnworking2 - - - - make a working directory for developer 2 pwd svn co file:///the_pwd_result/svnrepo/ ~/ svnworking1/ - - - - check out a working copy pretending be developer 1. ls svnworking1 - - - check new files in the directory ls svnworking1/trunk/ - - - check new files in the directory 26
PracKce- - - modify project and check in as Dev1 cd svnworking1/trunk vi try.txt - - - edit the file. - - - - go inside the directory. - - - - - now change the second line by adding something at its end. And save it and quit vi. svn status - - - - will see M try.txt. M stands for modified svn ci m change the second line - - - check in! 27
PracKce as Dev2 cd ~ pwd svn co file:///the_pwd_result/svnrepo/ ~/ svnworking2/ - - - - check out a working copy pretending be developer 2. ls svnworking2 ls svnworking2/trunk/ cd svnworking2/trunk/ vi try.txt - - - change the third line of the file by adding something at its end and then save the file and quit vi. svn ci m dev2 changed line 3 - - - check in! 28
PracKce - - - create a conflict cd ~ /svnworking1/trunk/ - - - - pretend as Dev1 vi try.txt - - - - - change the line 3 differently as Developer 2. And save the file and quit vi. svn ci m dev1 changed line 3 too - - - check in! - - - - Commit failed!!!- - - out of date!!! svn update - - - - has to update now! - - - - will see C try.txt means there is a conflict with try.txt ls - - - - Svn put 3 extra files in the directory and now 4 files are in the directory: try.txt try.txt.mine try.txt.r3 try.txt.r4 29
The Content of try.txt ARer Conflict the first line--remain the same the second line-- will change it.i add a word <<<<<<<.mine the third line-- will change it dev1 ======= the third line-- will change it dev2 add >>>>>>>.r4 the forth line--remain the same the fifth line--will change it the sixth line--will change and add a new line below the seventh line---remain the same the eighth line --will be deleted the ninth line --will be deleted the tenth line--remain the same then add some new lines. 30
PracKce - - - resolve the conflict vi try.txt - - - - - remove <<<<< ===== and >>>>> and make your decision what the final version should be! Save the file and quit vi. rm try.txt.* - - - - remove the three files: try.txt.mine try.txt.r3 try.txt.r4 that marked as conflict occurs. svn ci m dev1 resolve a conflict - - - check in! Congratulations!!! 31