Version Control Chonnam National University School of Electronics and Computer Engineering Kyungbaek Kim Original slides from James Brucker
What is version control Manage documents over time Keep a history of all changes Multiple versions of every file Coordinate work of multiple authors Avoid conflicts and help resolve them Permissions: authenticate and control access to files Show differences between versions of a file Document changes Reason for changes
How to use version control client checkout (first time) (do some work, test) check status update (resolve conflicts) commit (do more work, test) server send current revision ( n ) any changes since revision n? update your local copy with any changes in the repo. save your changes and log entry
Repository The server maintains a repository to store the version controlled data Clients check out copies of the data from the repository into its environment Working copies After making changes to working copies, clients commit changes to the repository After commit the revision number increases Other clients get these changes by updating their working copies
Repository Layout One repository, many projects Root Project 1 Project 2 trunk tags branches trunk tags branches One project per repository Repository parent dir Project 1 Project 2 trunk tags branches trunk tags branches Typically one repository per project Server can have an unlimited number of repositories
Inside of a Repository "KUClock" Project Repository revision 1 (initial repo structure) /var/svn/kuclock revision 4 revision 3 revision 2 revision 3: content diffs author date reason for change (comment) revision 2: initial project check-in...etc...
Revision numbers 0 1 2 3 Revision number is increased for every transaction that changes the repository.
Revisions User A checks out repository repo. repo/system.h 3 repo/system.cpp 3 User A modifies system.h and commits this file. repo/system.h 4 repo/system.cpp 3 User B commits changes to system.cpp, and A updates. repo/system.h 5 repo/system.cpp 5
Properties of a repository History of all changes to files and directories. you can recover any previous version of a file remembers "moved" and "deleted" files Access Control Read / write permission for users and groups Permissions can apply to repo, directory, or file Logging author of the change date of the change reason for the change
Logging a Revision Content Date Author Reason what has changed? when did it change? who changed it? why has it changed? SVN does this you enter this
Atomic commits A collection of modifications either goes into the repository completely, or not at all In other words, a commit will either altogether succeed, or it will altogether fail
Subversion Subversion is a version control system Usually called as SVN Subversion is well known and free Subversion fixes problems with CVS CVS : older version control system Subversion is being adopted as a replacement for CVS Subversion can manage any sort of file collection Not only source code
Subversion concepts checkout get a local copy of the files I have no files yet, how do I get them? add add a new file into the repository I created a new file and want to check it in commit send locally modified files to the repository I ve made changes, how do I send them to the group? update update all files with latest changes Other people made changes, how do I get them? tag / branch label a release I want to turn in a set of files
The Work Cycle of Subversion Create a local copy Submit your changes svn checkout svn update Make changes svn add svn move svn delete 100 Subversion Repository 106 105 svn commit Resolve conflicts (Merge your changes) svn diff svn resolved See what was changed in the repository in the meantime svn status -u Update your local copy svn update
Subversion Architecture Client Interface Repository Interface FSFS Apache GUI clients Cmd line clients Client Library Access Protocol DAV SVN SSH Intranetwork mod_dav mod_dav _svn svnserve sshd Subversion Repository Working Copy Management Library Local "file" protocol Berkley DB
How to create a repository Command Line svnadmin create repository_directory Graphical Tools Tortoise SVN Choose the option of creating repository here over a directory
How to contact a Subversion Server checkout (first time) client server 1. You need the URL of repository. http://se.cpe.ku.ac.th/svn/demo 2. (optional) may need a username and password.
URLs and Protocols http://myhost.com:port/path/to/repository Protocol: svn svn+ssh http https Host name or IP address 127.0.0.1 localhost host:8443 optional port number Repository relative path file
Examples of URLS http://altair.chonnam.ac.kr/svn/demo https://192.168.129.1:8080/svn/repo1 svn+ssh://user1@cam.kaist.ac.kr/svn/repo file:///home/user1/svn_test/repo
Checkout - Creating a working copy The client machine Repository Server Check out a "working copy"
Check Out List files in the repository svn list URL e.g., URL : file:///home/svn/repo/trunk Change the current directory to a suitable directory Check out the URL to a given directory name svn checkout URL Tips Don t check-out the entire repository Only check out the part that you need For developers, this is usually /repo/trunk For documenters, maybe /repo/doc
Checkout using TortoiseSVN Using windows Explore, right-click in a directory
Working copy.svn directory holds information of the repository and the working copy
Make changes You can add, move or delete files svn add file svn move src_file dest_file svn copy old_file new_file svn rename old_file new_file svn delete file Note : the commands work only in the working copy
Make changes using TortoiseSVN Results of changes
Commit changes You can commit your changes of working copy to the original copy at the repository svn ci [PATH]
Leave notes during commit
Update your working copy Before editing your work, check for updates in the repository Make your copy fresh svn up [PATH]
Update before editing You can not update your modification before update your working copy!!
Editing files You can edit files in your working repository If you have tortoisesvn, the explore indicates the change of your working copies Check your modification
Check the difference
What if conflicts happen? You can edit files, but Something might have changed while you were working Subversion requires you to synchronize before commit Conflict!! Means you have made changes to a file, and the version in the repository has been changed too
Resolving Conflicts Choices Merge local & remote changes into one file Accept remote, discard your local changes Override remote, use your local changes After resolving all conflicts, mark the file as resolved Subversion will delete the extra copies
SVN log viewer
export vs checkout export simply copy the target version of data svn [-r rev] URL [PATH] No.svn directory!!!
Import files Import : put the contents of a directory into the svn repository svn import [PATH] URL
Plan before you import Choose a directory layout for project and organize your copy src/ main/ java/ org/ myproject/ resources/ test/ java/... target/ classes/ site/ Source code Test code Build output, don't check-in to subversion
Plan before you import Decide what not to import Compiler output (*.class, *.obj, *.exe) Large image files, video, other data 3 rd party libraries you can get from Internet e.g. mysql-connector-5.1.jar.svnignore Put any file patterns and names of directories that you don t want to import into subversion
Ignore patterns 1. Through Setting 2. Individually adding
Tags Why do we need tags? Mark a release version of a product Mark a snapshot of the current development Typical Release names Release-0.1.2 major.minor.build(or revision) A tag name must be unique Contents of a tag should not be changed It depends on you!!
Tagging by Copy Root Project 1 trunk tags Release-1 Make references, not copy whole files
Branches This could happen to you You create a great product and it has been delivered to your customers Before you delivered the product you create a svn tag, named it Release-1.0.0 Your development team is modifying the trunk version with new features Customer reports that he found a major bug in your software
Branches You can keep developing the software And You create a branch to fix the bug RELEASE 1.0.0 BUGFIX_BRANCH RELEASE 1.0.1 Main line of development
Creating Branches Root Calc trunk Creating Branches is same to creating tags branches my-calc branch Paint trunk branches
Using branches : svn switch Switch the working copy in Trunk
Merging from a branch After fix the bug you need to merge the branched codes for further maintenance RELEASE 1.0.0 BUGFIX_BRANCH Merge back RELEASE 1.0.1
Merging from a branch
Branches vs tags The intention Tags : as read-only area Branches : as continue development area Technically you can use a tag to continue development and check in. But you should not do it!!