1CSE 391Lecture 9Version control with Gitslides created by Ruth Anderson & Marty Stepp, images from
2Problems Working Alone•Ever done one of the following?Had code that worked, made a bunch of changes and saved it, which broke the code, and now you just want the working version back…Accidentally deleted a critical file, hundreds of lines of code gone…Somehow messed up the structure/contents of your code base, and want to just “undo” the crazy action you just didHard drive crash!!!! Everything’s gone, the day before deadline.•Possible options:Save as (MyClass-v1.java)•Ugh. Just ugh. And now a single line change results in duplicating the entire file…
3Problems Working in teamsWhose computer stores the "official" copy of the project?•Can we store the project files in a neutral "official" location?Will we be able to read/write each other's changes?•Do we have the right file permissions?•Lets just email changed files back and forth! Yay!What happens if we both try to edit the same file?•Bill just overwrote a file I worked on for 6 hours!What happens if we make a mistake and corrupt an important file?•Is there a way to keep backups of our project files?How do I know what code each teammate is working on?
4Solution: Version Control•version control system: Software that tracks and manages changes to a set of files and resources.•You use version control all the timeBuilt into word processors/spreadsheets/presentation software•The magical “undo” button takes you back to “the version before my last action”Wiki’s•Wiki’s are all about version control, managing updates, and allowing rollbacks to previous versions
5Software Version control•Many version control systems are designed and used especially for software engineering projectsexamples: CVS, Subversion (SVN), Git, Monotone, BitKeeper, Perforce•helps teams to work together on code projectsa shared copy of all code files that all users can accesskeeps current versions of all files, and backups of past versionscan see what files others have modified and view the changesmanages conflicts when multiple users modify the same filenot particular to source code; can be used for papers, photos, etc.•but often works best with plain text/code files
6Repositories•Repository (aka “repo”): a location storing a copy of all files.you don't edit files directly in the repo; you edit a local working copy or “working tree”then you commityour edited files into the repo•There may be only one repository that all users share (CVS, Subversion) •Or each user could also have their own copy of the repository (Git, Mercurial)•Files in your working directory must be added to the repo in order to be tracked.