version control systems part 1
play

Version Control Systems (Part 1) Devin J. Pohly - PowerPoint PPT Presentation

Systems and Internet i Infrastructure Security i 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.


  1. Systems and Internet i Infrastructure Security i 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> CMPSC 311: Introduction to Systems Programming Page 1

  2. 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 CMPSC 311: Introduction to Systems Programming Page 2

  3. 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 CMPSC 311: Introduction to Systems Programming Page 3

  4. 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 CMPSC 311: Introduction to Systems Programming Page 4

  5. 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 repository • Check in/commit: add a new revision to repository CMPSC 311: Introduction to Systems Programming Page 5

  6. 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” CMPSC 311: Introduction to Systems Programming Page 6

  7. 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 CMPSC 311: Introduction to Systems Programming Page 7

  8. RCS usage • Extremely simple • Check out (read-only) ‣ rcs co foo.h • Check out and lock ‣ rcs co -l foo.c • Check in and commit changes ‣ rcs ci foo.c CMPSC 311: Introduction to Systems Programming Page 8

  9. How RCS works Alice Repository Bob foo.c 1.1–1.12 foo.h 1.1–1.5 main.c 1.1–1.50 • Each file has its own repository in the RCS directory, in which all of that file’s revisions are stored CMPSC 311: Introduction to Systems Programming Page 9

  10. How RCS works rcs co foo.h rcs co foo.h Alice Repository Bob foo.c 1.1–1.12 foo.h foo.h foo.h 1.5 1.5 1.1–1.5 main.c 1.1–1.50 • Anyone can check out a read-only working copy of a file. CMPSC 311: Introduction to Systems Programming Page 10

  11. How RCS works rcs co -l foo.c Alice Repository Bob foo.c foo.c 1.12 1.1–1.12 foo.h foo.h foo.h 1.5 1.5 1.1–1.5 main.c 1.1–1.50 • If Alice wants to make changes to foo.c, she must lock the file for writing when she checks it out. CMPSC 311: Introduction to Systems Programming Page 11

  12. How RCS works vim foo.c rcs co -l foo.c Alice Repository Bob foo.c foo.c 1.12 1.1–1.12 foo.h foo.h foo.h 1.5 1.5 1.1–1.5 main.c 1.1–1.50 • Once Alice has locked foo.c, nobody else may lock it. • Alice can now safely edit her local copy of the file. CMPSC 311: Introduction to Systems Programming Page 12

  13. How RCS works vim foo.h rcs ci foo.c rcs ci foo.h Alice Repository Bob foo.c foo.c 1.12 1.1–1.12 foo.h foo.h foo.h 1.5 1.5 1.1–1.5 main.c 1.1–1.50 • You can only commit changes to a file if you hold the lock. • Committing foo.c checks in Alice’s changes as a new revision, then unlocks the file so others can lock it. CMPSC 311: Introduction to Systems Programming Page 13

  14. How RCS works Alice Repository Bob foo.c 1.1–1.13 foo.h foo.h foo.h 1.5 1.5 1.1–1.5 main.c 1.1–1.50 • When Alice commits her modified foo.c, the repository creates the new revision number 1.13. CMPSC 311: Introduction to Systems Programming Page 14

  15. 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 CMPSC 311: Introduction to Systems Programming Page 15

  16. How Subversion works Alice Bob Repository 1–56 foo.c foo.h main.c • Spot the differences! CMPSC 311: Introduction to Systems Programming Page 16

  17. How Subversion works Alice Bob Repository 1–56 foo.c foo.h main.c • Files are stored in one repository rather than individual ones. • Repository and users can all be on different hosts. CMPSC 311: Introduction to Systems Programming Page 17

  18. How Subversion works svn checkout URL svn checkout URL Alice Bob foo.c foo.c Repository 1–56 foo.h foo.h foo.c foo.h main.c main.c main.c • Checkout does the same thing: gets a working copy of the latest revision (which now contains all the files) from the repository. • You don’t have to lock files to change them. CMPSC 311: Introduction to Systems Programming Page 18

  19. How Subversion works vim foo.c vim foo.h svn commit Alice Bob foo.c foo.c Repository 1–56 foo.h foo.h foo.c foo.h main.c main.c main.c • If Alice modifies some files and commits her changes... CMPSC 311: Introduction to Systems Programming Page 19

  20. How Subversion works Alice Bob foo.c foo.c Repository 1–57 foo.h foo.h foo.c foo.h main.c main.c main.c • ... a new revision of the repository (r57) is created. CMPSC 311: Introduction to Systems Programming Page 20

  21. How Subversion works vim main.c svn commit Alice Bob foo.c foo.c Repository 1–57 foo.h foo.h foo.c foo.h main.c main.c main.c • If Bob makes changes that don’t overlap with Alice’s, Subversion can merge them automatically. • This is what happens most of the time. CMPSC 311: Introduction to Systems Programming Page 21

  22. How Subversion works vim foo.c svn commit Alice Bob foo.c foo.c Repository 1–57 foo.h foo.h foo.c foo.h main.c main.c main.c • If Subversion can’t merge the changes automatically, it notifies Bob that there is a merge conflict . CMPSC 311: Introduction to Systems Programming Page 22

  23. How Subversion works svn update vim foo.c svn commit Alice Bob foo.c foo.c Repository 1–57 foo.h foo.h foo.c foo.h main.c main.c main.c • So Bob updates his repository with Alice’s changes, merges them with his, and tries to commit again. CMPSC 311: Introduction to Systems Programming Page 23

  24. How Subversion works Alice Bob foo.c foo.c Repository 1–58 foo.h foo.h foo.c foo.h main.c main.c main.c • Bob’s commit succeeds this time, creating revision 58, which is then stored in the repository. CMPSC 311: Introduction to Systems Programming Page 24

  25. Commit graphs SVN repository 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.) CMPSC 311: Introduction to Systems Programming Page 25

  26. The third generation • Distributed VCSes • 2000s to today • Bazaar, Git , Mercurial • Seeing widespread use • Everyone has a full repository • Highly collaborative ‣ Linux development ‣ GitHub and other “social coding” sites CMPSC 311: Introduction to Systems Programming Page 26

  27. Sharing your revisions • When you commit your changes, the revision is stored in your local repository • All communication is between repositories ‣ You push local revisions to a remote repository... ‣ and you pull revisions from a remote repository into the local one. CMPSC 311: Introduction to Systems Programming Page 27

  28. How Git works Alice Bob “Official” repository .. A foo.c foo.h main.c • Spot the differences CMPSC 311: Introduction to Systems Programming Page 28

  29. How Git works Alice Bob “Official” repository .. A foo.c foo.h main.c • Alice and Bob will both have their own repositories, no different from the “official” one. CMPSC 311: Introduction to Systems Programming Page 29

  30. How Git works git clone URL git clone URL Alice Bob Alice’s “Official” Bob’s repository repository repository .. A .. A .. A foo.c foo.c foo.c foo.h foo.h foo.h main.c main.c main.c • First step is to clone the repository, not check it out. • This gives you a local clone of the entire repo! CMPSC 311: Introduction to Systems Programming Page 30

  31. How Git works git checkout Alice A foo.c Alice’s repository .. A foo.h foo.c foo.h main.c main.c • Alice can now work locally (and offline), without worrying about other repositories. CMPSC 311: Introduction to Systems Programming Page 31

  32. How Git works vim foo.c git add foo.c git commit Alice A foo.c Alice’s repository .. A foo.h foo.c foo.h main.c main.c • Alice edits foo.c as usual, adds her changes to the new revision, and commits it. CMPSC 311: Introduction to Systems Programming Page 32

  33. How Git works Alice B foo.c Alice’s repository .. B foo.h foo.c foo.h main.c main.c • Revision B, based on A, is now in Alice’s repository. CMPSC 311: Introduction to Systems Programming Page 33

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend