SC2012BootcampPlan » History » Version 46

Chris Cannam, 2012-04-26 04:32 PM

1 1 Chris Cannam
h1. Plan for Software Carpentry 2012 Boot Camp on Version Control
2 1 Chris Cannam
3 43 Chris Cannam
h2. About the session
4 1 Chris Cannam
5 43 Chris Cannam
The session is a two hour interactive live workshop, using EasyMercurial and the Mercurial command-line tool.
6 2 Chris Cannam
7 43 Chris Cannam
Its goal is to explain version control and introduce Mercurial to researchers who have never used it before, or who want to understand it better.
8 1 Chris Cannam
9 1 Chris Cannam
h2. Outline
10 2 Chris Cannam
11 3 Chris Cannam
The basic plan is:
12 1 Chris Cannam
13 43 Chris Cannam
 # Presentation introduction to version control in general (using either whiteboard drawings or a PowerPoint presentation)
14 43 Chris Cannam
 # Long worked example in which basic topics of version control are worked through using EasyMercurial and then some more advanced topics are returned to using the command-line tool
15 43 Chris Cannam
 # Closing remarks talking about other tools, other topics of interest etc
16 3 Chris Cannam
17 43 Chris Cannam
h2. Worked example
18 7 Chris Cannam
19 43 Chris Cannam
Preliminary: Check that participants have EasyMercurial installed and working. All of the following exercises will be using EasyMercurial unless it says otherwise.
20 7 Chris Cannam
21 43 Chris Cannam
h3. Part 1: Working by yourself
22 43 Chris Cannam
23 43 Chris Cannam
*Topics:* Initialising a repository, committing files, reading history, looking at diffs, reverting unwanted changes, going back in time to look at old versions
24 43 Chris Cannam
25 44 Chris Cannam
We will be working on a recipe for fish stew for a future recipe book.
26 44 Chris Cannam
27 45 Chris Cannam
h4. Adding your first file
28 44 Chris Cannam
29 44 Chris Cannam
 * Make a new directory, create a text file @fishstew.txt@ in it, start adding an ingredients list, save
30 44 Chris Cannam
 * Run up EasyMercurial, "Open" that directory, see @fishstew.txt@ in untracked file list: that means the version control system is not going to keep track of any changes unless we tell it to
31 44 Chris Cannam
 * Add file: that tells the version control system to keep track of any future changes to it
32 44 Chris Cannam
 * Commit: that sets in stone our having added the file. A commit is a checkpoint
33 44 Chris Cannam
 * Supply a message, note that we now have some history
34 44 Chris Cannam
35 44 Chris Cannam
h4. Changing things
36 44 Chris Cannam
37 44 Chris Cannam
 * Edit the file, change something, save it
38 44 Chris Cannam
 * Note that the file is now marked as modified. (We might also see a backup file ending ~ or .bak from that editor -- _we'll come back to that in a moment_)
39 44 Chris Cannam
 * Each revision records the state of all files, not just one file: add another file, @omelette.txt@ and add that
40 44 Chris Cannam
 * Commit change, note that we now have two revisions
41 44 Chris Cannam
 * Review the history and look at the diff
42 44 Chris Cannam
43 44 Chris Cannam
_Digression: every action we're taking here corresponds to one command-line command: show hg log, hg diff etc_
44 44 Chris Cannam
45 44 Chris Cannam
 * Go back to that backup file in My Work, add it to ignored list, commit
46 44 Chris Cannam
47 44 Chris Cannam
h4. Managing history
48 44 Chris Cannam
49 44 Chris Cannam
 * The history is not just for information: we can go back to the previous version by updating to it...
50 44 Chris Cannam
 * ... and then a normal update gets us back to the latest version again
51 44 Chris Cannam
52 44 Chris Cannam
Let's say this version is the one that we're going to send off to our agent, to see whether they can sell it to a publisher (or whatever we do in these modern times).
53 44 Chris Cannam
54 44 Chris Cannam
 * Tag the current revision as v0.1 -- _digression about sensible tag names on whiteboard?_
55 44 Chris Cannam
 * We can now identify this version easily in the history
56 44 Chris Cannam
 * Make and commit another change, this one involving renaming a file
57 44 Chris Cannam
 * What if we make a change and decide we don't want to commit it? Edit something, then hit Revert
58 44 Chris Cannam
59 44 Chris Cannam
Now we have history, but we are still in big trouble if our computer fails. Thus...
60 44 Chris Cannam
61 44 Chris Cannam
h3. Part 2: Working by yourself, but "with backups"
62 44 Chris Cannam
63 44 Chris Cannam
*Topics:* Clone, push and pull, using an online repo
64 44 Chris Cannam
65 46 Chris Cannam
h4. Push our local repository to a remote one
66 46 Chris Cannam
67 46 Chris Cannam
 * Register an account on Bitbucket and create a new private repository
68 46 Chris Cannam
 * Look up its URL
69 46 Chris Cannam
 * In EasyMercurial, hit the Push button, enter URL, push to remote repo, check that the history is present and correct on the site
70 46 Chris Cannam
71 46 Chris Cannam
h4. Synchronise new changes
72 46 Chris Cannam
73 46 Chris Cannam
 * Make another change locally, commit (perhaps do this more than once before pushing)
74 46 Chris Cannam
 * Push the change(s), and check the history on site again
75 46 Chris Cannam
76 46 Chris Cannam
h4. Recover from a disaster
77 46 Chris Cannam
78 46 Chris Cannam
 * Exit EasyMercurial. Delete the local repository / working copy folder completely!
79 46 Chris Cannam
 * Start EasyMercurial again, see that _(sniff)_ the working copy is lost
80 46 Chris Cannam
 * Clone it again from Bitbucket and note that the history is all there
81 46 Chris Cannam
82 46 Chris Cannam
_Digression: Note command-line usage again, hg push, hg pull, hg clone: show a sequence of clones, modifying the last one and pushing back along the chain?_
83 46 Chris Cannam
84 23 Chris Cannam
 * *Worked example, part 3: Introducing other developers*
85 22 Chris Cannam
 ** *Topics:* Conflicts, merges
86 21 Chris Cannam
 ** Pair up and, in each pair, decide whose Bitbucket repo you will be working on and whose we'll just leave for now. (We should pair the "instructor" with someone as well)
87 33 Chris Cannam
 ** Remark: in real-world use, this could very well be the same person just using two different computers
88 21 Chris Cannam
 ** The second person in the pair should then clone the repository from Bitbucket
89 24 Chris Cannam
 ** Both people can then make some edits: they should edit the same file
90 24 Chris Cannam
 ** The _second_ user should push their changes to the remote repo first
91 24 Chris Cannam
 ** The _first_ user then tries to push. They should get the "Push failed... The local repository may have been changed" message
92 33 Chris Cannam
 ** Then the first user pulls instead. (Perhaps checks the Incoming list first?) History graph now shows two heads -- _digression on sociological nature of conflict_ a la Greg if feeling expansive
93 30 Chris Cannam
 ** Hit Merge, get the merge window up. Do an "instructor-guided" merge
94 30 Chris Cannam
 ** Commit, push, get collaborator to pull
95 31 Chris Cannam
 ** Run annotate (blame) on the recipe to see who changed what and when
96 31 Chris Cannam
 * *Worked example, part 4: More sophisticated business at the command-line*
97 31 Chris Cannam
 ** @hg archive@: packaging from a tag
98 31 Chris Cannam
 ** @hg id@: provenance when running experiments
99 38 Chris Cannam
 ** @hg bisect@: finding the origin of bugs you can't see (analogy with @hg annotate@ for finding bugs you can see)
100 1 Chris Cannam
 
101 42 Chris Cannam
Things not yet incorporated into the above: Copying, renaming, deleting files; Branching and merging amonst branches; Stuff that is different in other systems
102 1 Chris Cannam
103 37 Chris Cannam
Should we cover (named) branches and merges between them? I think yes, if there is time.
104 31 Chris Cannam
105 1 Chris Cannam
Against: perhaps a level of complication too far for a two-hour intro; Greg doesn't cover them in the Subversion version; lessons learned from Hg are not immediately applicable to git or Subversion because the branching methods are somewhat different.
106 32 Chris Cannam
107 32 Chris Cannam
For: they are much simpler to use in Mercurial than in Subversion!
108 40 Chris Cannam
109 40 Chris Cannam
h2. Quiz
110 40 Chris Cannam
111 40 Chris Cannam
The Software Carpentry Subversion course includes a quiz -- I like quizzes. Let's try adjusting the questions for Mercurial:
112 40 Chris Cannam
113 41 Chris Cannam
 * Why is it a good idea to use version control on your projects?
114 41 Chris Cannam
 * What is a version control repository?
115 41 Chris Cannam
 * Suppose you’ve created a new file on your computer and you want to start using version control for it. How do you go about doing this?
116 41 Chris Cannam
 * Jon is working on a version-controlled project with Ainsley and Tommy. He wakes up early one day, ready to do some work on the project. What is the first thing he should do?
117 41 Chris Cannam
 * Tommy and Jon have up-to-date local repositories, and are both editing a file that contains 10 lines of data. Jon makes a change to the fifth line, and commits and pushes his changes to the remote repository they're both using. Tommy makes a change to the first line of the file, commits his changes, and tries to push them. What will happen, and what should Tommy do next?
118 41 Chris Cannam
 * Ainsley and Jon are up-to-date, and are both editing the sixth line of a file. Jon commits and pushes his changes first. When Ainsley commits and tries to push, what will happen, and what should she do next?
119 41 Chris Cannam
 * How do you undo local changes to files that have not been committed?
120 40 Chris Cannam
 * Give the shell commands you would use to accomplish the following tasks:
121 40 Chris Cannam
122 41 Chris Cannam
    Check out the repository located at http://example.com/repo into the directory /cygwin/home/repo
123 41 Chris Cannam
    View the log of changes
124 41 Chris Cannam
    Add the file “experiment.txt” to the repository
125 41 Chris Cannam
    Commit the file to the repository.
126 41 Chris Cannam
    Update the local copy to reflect any new changes in the remote repository