Open Source Comes to Campus/Resources: Difference between revisions

imported>Shauna
imported>Shauna
==Introduction to Version Control==
 
This talk is assuming you are speaking at Wellesley College. You're probably not going to be speaking at Wellesley, so you'll need to make a handful of changes. For instance, it is highly recommended that you browse through the wikiwikipedia page history of your campus's school ahead of time to find a fun edit to use as an example.
 
'''Why version control'''
 
* HowI many ofwant you haveto everthink back to the last time you worked on a groupbig project?. (PauseCould be for handsschool, could be for some other purpose. (Take a moment to let them raisedthink.) How many of you havepeople worked on a groupthat project? spanning multiple(Get draftsanswers.) or iterations,How orlong thatdid tookyou awork fewon weeksit? or even(Get longeranswers.) to complete?How many (Pauseseparate forpieces handsdid it have? (Get raisedanswers.)
* HowNow here's the real question - how did you keep track of differentthe peoplechanges workingthat on differentyou filesmade?
** Some people will say they emailed around different copies of files.
** Others may say that they had people all working in person and talking about changes.
** Some will probably mention version control systems.
* How well did that work out?
** How well did that work out? (Attendees will typically chuckle.)
* All sorts of problems can crop up when you're working on a project. What if you don't like the changes you made and you want to go back to how things were? What if multiple people want to make changes to the same file at the same time? What if you have some sort of class clown in your group who keeps going through and changing random words to 'Batman'? How do you handle that.
* So,The yeah,answer: oneversion common way to do that is to email around copies of a file you're working oncontrol. A different way is to use whatIt's called version control, where there is a system for tracking different versions of a file. The most popular tools let every contributor keep a copy of the project on their own computer, making whatever changes they want, and eventually synchronizing with the rest of the team.
 
'''Wikipedia'''
* Okay, so imagine you're working on a project with about 19 million other people, editing 4 million files?
 
* That's Wikipedia. As you can imagine, they've put a lot of thought into version control. Let's go look at how they do it. (Navigate web browser to http://en.wikipedia.org/wiki/Wellesley_College )
* To talk about version control, I want to show you how version control works for purely text documents. So let's look at the Wikipedia page for Wellesley College.
* So one of the great things about Wikipedia is that the system keeps every track of every version of every article. The wiki system is a version control system, too. If you click on the "Edit" tab, you can see the built in way to edit every article. Let's take a look at the ''history'' tab here. (click history tab; zoom in so it's large enough for people to see; make it really enormous)
* (Navigate web browser to http://en.wikipedia.org/wiki/Wellesley_College )
* So one of the great things about Wikipedia is that the system keeps every track of every version of every article. The wiki system is a version control system, too. If you click on the "Edit" tab, you can see the built in way to edit every article. Let's take a look at the ''history'' tab here. (click history tab)
* (find yourself at http://en.wikipedia.org/w/index.php?title=Wellesley_College&action=history ; zoom in so it's large enough for people to see; make it really enormous)
* So here, you can see a little heading for every version of the page, including (mouse over the date) the time and date of that version, who saved that version, and a brief summary of what the changes are. Here, the most recent version says +73 -- that means that 73 characters were added in that revision.
* One standard feature of version control tools is to be able to see each version of the file. On Wikipedia, you can do that by clicking on the date. (click on the most recent edit, taking you to e.g. http://en.wikipedia.org/w/index.php?title=Wellesley_College&oldid=559029901 )
** (click on the most recent edit, taking you to e.g. http://en.wikipedia.org/w/index.php?title=Wellesley_College&oldid=559029901 )
** You can see the box at the top that says, "This is the current revision of the page." The real thing going on here is that we're using an identifier for the page that will never change, even if the page gets edited, because we're looking at the particular revision.
* Let's hit back, and take a look at an older version that has an edit summary. In this case, we see they say they added a note about New Zealand. When we click the date (Click the date)... and load the page, we can see visually that the page seems to have a note about New Zealand. But we don't know just from looking at this version of the page if maybe they made other changes.
* You folks already saw diffs, and like most version control tools, Wikipedia lets you see a diff between the two pages. It's line-based, like a lot of tools used in programming. Let's click back... (back to http://en.wikipedia.org/w/index.php?title=Wellesley_College&action=history ) and instead of clicking on the date, we'll select this revision as the first item selected, and the one right after it as the one we want to diff against. When we click "Compare selected revisions", it takes us to a page like http://en.wikipedia.org/w/index.php?title=Wellesley_College&diff=558216275&oldid=556114296
** On that page, you can see the one '''+''' line: the addition of this link to a different school in New Zealand. In particular, this shows us that there are no changes other than the particular one about the new link.
* One key difference between wikipedia's version control system and most others is that Wikipedia's default is to accept contributions. If you make a change, it will instantly go live. In fact, let's make a change now. (Make a minor edit.) Now, someone could come along and revert the change. They could even ban our account, if they think we're acting in bad faith. But this edit will still have been part of the current version for a brief period of time. In most other version control systems, a change has to be reviewed and approved before it goes live.
 
'''Different version control tools out there'''
** Then there are some code hosting sites that work with different types of version control systems. Github works with git. Google Code works with git, mercurial, and subversion. Bitbucket works with mercurial and git. Again, there are other hosting sites, too many to mention here.
** If you're trying to work on a project but you're having trouble understanding their version control system, check and see which one it is. We have training missions on Openhatch.org for using git and subversion, and can likely help you informally on #openhatch if it's some other system.
* To get back to git, which is again the most popular tool and the one we'll be teaching you about today.
 
** Git calls your revisions commits. This refers not to changes to individual files, but to the state of the project at a given point. Here's a list of commits (https://github.com/bundestag/gesetze/commits/master, then click on an individual hexadecimal #) which you can see sometimes involve changes to one file, and sometimes to more. You can also see the diff between this commit and the previous one. You get to decide how frequently to bundle your changes into commits. I personally commit frequently and compulsively.
** One moreAnother difference is how the version numbers are encoded. In git, the revision number is a checksum of all the important information about the commit: the name and email address of the person who made the change, plus the contents of the files that are part of the commit, plus a timestamp of when the commit was made, plus a few other bits of data. In some systems, the version numbers are just numbers that increase over time. With git, since every person uses their own computer and can make commits whenever they want, the commit IDs can't collide, so they're computed based on the content.
 
'''Other things you can use version control for'''
 
* A lot of people use version control for code, but as we can see with wikipedia that's not the only use for it. You can use version control on almost anything digital. For instance:
* Again, one difference here is that Wikipedia is the encyclopedia that anyone can edit. For Wikipedia, that means that as soon as we edit a page, it's automatically live. For open source software projects, or the German legal system, there's often a review process -- you can use version control to prepare a diff and share it, and if the maintainer likes it, they ''merge'' it into the main project.
** (ClickThere "Commits"have --been several efforts to keep track of legislation via version control systems. For instance, [https://github.com/bundestag/gesetze/commits/master )Gesetze] follows the German Bundestag.
** The White House has put part of [https://github.com/project-open-data their open data initiative] on Github and has been accepting issues and pull requests.
* Another difference is that in git, revisions are called commits. They track not just changes to one file, but the entire state of the project at that time. So when you click "Browse code" at the most recent commit, it takes you to e.g. https://github.com/bundestag/gesetze/tree/ee428461b034de54f1cdcab524d2808486383677 which shows you the entire project.
** The [https://github.com/Chicago city of Chicago] has started sharing its open data via Github.
** Usually you are just interested in the difference between this commit and the previous commit, so Github makes that easy: you just click on this short hexadecimal number, and it shows you a diff.
** Hundreds of people have put up [https://github.com/search?q=poetry repositories of poetry], and a friend of mine uses git to keep track of her novel.
** One more difference is how the version numbers are encoded. In git, the revision number is a checksum of all the important information about the commit: the name and email address of the person who made the change, plus the contents of the files that are part of the commit, plus a timestamp of when the commit was made, plus a few other bits of data. In some systems, the version numbers are just numbers that increase over time. With git, since every person uses their own computer and can make commits whenever they want, the commit IDs can't collide, so they're computed based on the content.
** Some educators are [http://chronicle.com/blogs/profhacker/how-to-fork-a-syllabus-on-github/39447 sharing syllabi].
* So, in a nutshell, those are the key notions behind version control, and git. Now's a great time for questions! After the questions, we'll take some time to work through a training mission to give you hands on experience in git and how projects use it.
** Some scientists are [https://caseybergman.wordpress.com/2012/11/08/on-the-preservation-of-published-bioinformatics-code-on-github/ publishing their raw data], as well as the scripts they use for processing and analyzing it, on Github.
 
'''Exercises & Follow up'''