i i Systems and Internet Infrastructure Security Institute for Networking and Security Research Department of Computer Science and Engineering Pennsylvania State University, University Park, PA Version Control Systems (Part 1) Devin J. Pohly <djpohly@cse.psu.edu> Page 1
Version control systems A version control system is a system for keeping track of the changes made to a document (or collection of documents) over time Any kind of document... Resumes Source code TPS reports Page 2
Why? It s a time machine! Look at old versions Never lose anything Revert your mistakes Code fearlessly! Collaboration Work in parallel Merge changes Social coding Page 3
A word about words These terms all refer to the same thing: Version control system Revision control system Source code/control management VCS/RCS/SCM For this lecture: version control and VCS Page 4
Basic concepts Revision: one meaningful change or set of changes Repository: where all of the revisions are stored Working copy: copy of one revision, where the user makes changes Check out: get a working copy from Check in/commit: add a new revision to Page 5
Basic concepts Branches: parallel lines of development Trunk/master: main development branch Tip/head: latest revision on a branch Tag: special name given to an important revision Often used for numbered releases like v4.0 Page 6
The first generation Local VCSes 1970s and 80s SCCS, RCS Repository stored in a shared local directory User must lock a file before making changes Lock-edit-unlock model Page 7
RCS usage Extremely simple Check out (read-only) rcs co Check out and lock rcs co -l Check in and commit changes rcs ci Page 8
How RCS works Repository 1.1 1.12 1.1 1.5 1.1 1.50 Each file has its own in the RCS directory, in which all of that file s revisions are stored Page 9
How RCS works rcs co rcs co Repository 1.1 1.12 1.5 1.1 1.5 1.5 1.1 1.50 Anyone can check out a read-only working copy of a file. Page 10
How RCS works rcs co -l Repository 1.12 1.1 1.12 1.5 1.1 1.5 1.5 1.1 1.50 If wants to make changes to, she must lock the file for writing when she checks it out. Page 11
How RCS works vim rcs co -l Repository 1.12 1.1 1.12 1.5 1.1 1.5 1.5 1.1 1.50 Once has locked, nobody else may lock it. can now safely edit her local copy of the file. Page 12
How RCS works vim rcs ci rcs ci Repository 1.12 1.1 1.12 1.5 1.1 1.5 1.5 1.1 1.50 You can only commit changes to a file if you hold the lock. Committing checks in s changes as a new revision, then unlocks the file so others can lock it. Page 13
How RCS works Repository 1.1 1.13 1.5 1.1 1.5 1.5 1.1 1.50 When commits her modified, the creates the new revision number 1.13. Page 14
The second generation Centralized VCSes 1980s to 2000s CVS, Subversion (SVN) Still widely used Repository on a server with many clients Copy-modify-merge model Page 15
How Subversion works Repository 1 56 Spot the differences! Page 16
How Subversion works Repository 1 56 Files are stored in one rather than individual ones. Repository and users can all be on different hosts. Page 17
How Subversion works svn checkout URL svn checkout URL Repository 1 56 Checkout does the same thing: gets a working copy of the latest revision (which now contains all the files) from the. You don t have to lock files to change them. Page 18
How Subversion works vim vim svn commit Repository 1 56 If modifies some files and commits her changes... Page 19
How Subversion works Repository 1 57... a new revision of the (r57) is created. Page 20
How Subversion works vim svn commit Repository 1 57 If makes changes that don t overlap with s, Subversion can merge them automatically. This is what happens most of the time. Page 21
How Subversion works vim svn commit Repository 1 57 If Subversion can t merge the changes automatically, it notifies that there is a merge conflict. Page 22
How Subversion works svn update vim svn commit Repository 1 57 So updates his with s changes, merges them with his, and tries to commit again. Page 23
How Subversion works Repository 1 58 s commit succeeds this time, creating revision 58, which is then stored in the. Page 24
Commit graphs SVN 56 57 58 By convention, the arrow points from the child revision to the parent revision. Every branch in Subversion or RCS has an entirely linear commit graph. (Branches are linearized when you merge them.) Page 25
The third generation Distributed VCSes 2000s to today Bazaar, Git, Mercurial Seeing widespread use Everyone has a full Highly collaborative Linux development GitHub and other social coding sites Page 26
Sharing your revisions When you commit your changes, the revision is stored in your local All communication is between repositories You push local revisions to a remote... and you pull revisions from a remote into the local one. Page 27
How Git works Official..A Spot the differences Page 28
How Git works Official..A and will both have their own repositories, no different from the official one. Page 29
How Git works git clone URL git clone URL s..a Official..A s..a First step is to clone the, not check it out. This gives you a local clone of the entire repo! Page 30
How Git works git checkout A s..a can now work locally (and offline), without worrying about other repositories. Page 31
How Git works vim git add git commit A s..a edits as usual, adds her changes to the new revision, and commits it. Page 32
How Git works B s..b Revision B, based on A, is now in s. Page 33
How Git works s A B In our Git example, has committed revision B onto revision A. Page 34
How Git works s A B C In our Git example, has committed revision B onto revision A. She can then commit another revision C onto that. Page 35
Push and pull in Git git push s..c A..C Official..A s..b' can push her new revisions to another, such as the official one. The revision being pushed must be a descendant of the remote one. Page 36
Push and pull in Git s..c Official..C s..b' The official now contains s changes. Notice has also committed B' but not yet pushed! Page 37
Push and pull in Git s A B s commit graph has his new revision, but none of s. Page 38
Push and pull in Git git push s..c Official..C s..b' cannot push his changes yet, because B' is not a descendant of C. Page 39
Push and pull in Git git pull s..c Official..C A..C s..b' needs to get s new changes and merge them. First he pulls the revisions from the official repo... Page 40
Git merges s A B C B'... and they are added to his. He can now merge s changes with his. Page 41
Git merges s A B B' C D This creates a new merge revision D which has two parents: B' and C. Page 42
Coming full circle git push s..c Official..C s..d Since D is a descendant of C, can now push! Page 43
Coming full circle s..c Official..D s..d The official now has revision D, which contains both s and s changes. Page 44
Coming full circle git pull BOB_URL s..c Official..D s..d C..D Developers can also collaborate directly. Here gets s latest revisions directly from himself rather than from the official. Page 45
Coming full circle s..d Official..D s..d This could be used, for instance, to collaborate on experimental features that aren t ready for prime-time. Page 46
Trends in version control Isolated to collaborative Serial to concurrent Linear to branching Centralized to distributed Limited workflows to many possibilities Page 47