2 ----------------------------------------------------------------------------------
3 What is Version Control
4 ----------------------------------------------------------------------------------
6 Very briefly, version control is a way to keep a backup of changing files, to
7 store a history of those changes, and most importantly to allow many people in
8 a collaboration to make changes to the same files concurrently. There are a lot
9 of verson control systems. Wikipedia provides both a nice vocabulary list and a
10 fairly complete table of some popular version control systems and their
13 Today, we'll be using SVN. Perhaps someday we'll have a second section of this
14 experiment to go over distributed version control systems like mercurial.
16 ----------------------------------------------------------------------------------
18 ----------------------------------------------------------------------------------
20 The Hacker Within has its own online code repository. You can check out code
21 from it at any time, from anywhere. You checked out some code this morning from
22 it at googlecode http://code.google.com/p/scbc-2011 in smartsvn. If you gave me
23 a google id, you are a fully fledged reading writing member today. Remember,
24 with great power comes great responsibility.
26 Today, we'll check out an svn type repository at scbc-2011.googlecode.com/svn/
29 **********************************************************************************
30 Exercise : Checking out the code
31 **********************************************************************************
33 Step 1 : Open up an internet browser and log in to google.
35 Step 2 : Now go to the Checkout the source tab and click on the Password link.
38 Step 3 : Either do this in SmartSVN or crack open a terminal. In SmartSVN,
39 click on the radio button that says check out project from repository. The
40 repository location is https://scbc-2011.googlecode.com/svn/ .
42 In the terminal, if your google user name is buckybadger, do this:
46 ~$ svn checkout https://scbc-2011.googlecode.com/svn/ \
47 scbc-2011 --username buckybadger
49 Step 4 : You should see many files download themselves onto your machine. Let's
50 make sure it worked. Either browse in SmartSVN or change directories to the
51 source code and list the contents.
55 ~$ cd scbc-2011 ~/scbc-2011$ ls
58 ----------------------------------------------------------------------------------
59 Checking The Status of Your Local Copy
60 ----------------------------------------------------------------------------------
62 The files you've created on your machine are your local "working" copy. The
63 changes your make in this local copy aren't backed up online automatically.
64 Until you commit them, the changes you make are local changes. When you change
65 anything, your set of files becomes different from the files in the official
66 repository copy. To find out what's different about them in the terminal, try:
70 ~/scbc-2011$ svn status
73 The null result means that you're up to date with the
74 current version of the repository online! There are a few other responses you
75 might get if you or your collaborators have been active. We'll see what they
78 ----------------------------------------------------------------------------------
80 ----------------------------------------------------------------------------------
82 Updating is like voting. You should update early and often , and particularly
83 before you make or commit any changes. This will ensure you're working with the
84 most up-to-date version of the repository. Updating won't overwrite any changes
85 you've made locally without asking, so don't get nervous. When in doubt,
90 ~/scbc-2011$ svn update
93 ----------------------------------------------------------------------------------
94 Adding New Files to Version Control
95 ----------------------------------------------------------------------------------
97 This is great. You can make some changes, and commit them to version control.
98 But, what if you want to add something totally new? How do you make changes to
99 a file that doesn't exist yet?
101 **********************************************************************************
102 Exercise : Adding files to Version Control
103 **********************************************************************************
105 Step 1: Create a wiki page about yourself. Please tell us about yourself. Save
106 a file to the folder called wiki. Call it something unique, like
107 buckybadger.wiki. Take your time.
111 ~/scbc-2011$ vi buckybadger.wiki
113 Step 2: Check the status of your local copy For kicks, let's see what SVN
118 ~/scbc-2011$ svn status
120 SVN should report that it hasn't yet been officially introduced to your file.
126 Step 3: Add the file to version control Now, introduce your file to svn by
127 adding it to version control.
131 ~/scbc-2011$ svn add wiki/buckybadger.wiki
132 A wiki/buckybadger.wiki
134 If you want to, commit that change. Your wiki page will be available for anyone
135 to see on the repo. When your done, give it a look online at
136 scbc-2011.googlecode.com/wiki.
140 ~/scbc-2011$ svn commit -m "In commit messages, we usually explain what we've \
141 done. Here, we've added a wiki page."
142 Adding wiki/buckybadger.wiki
143 Transmitting file data .
144 Committed revision 86.
146 ----------------------------------------------------------------------------------
147 Removing Files from Version Control
148 ----------------------------------------------------------------------------------
150 But, let's say you're shy and change your mind about adding this to version
151 control. Not all pretty faces belong on the internet, after all. If you change
152 your mind, and would rather not add this wiki page, try svn remove. You can
153 also just say rm. Be careful, this will delete your local copy of the file.
157 ~/scbc-2011/wiki$ svn remove buckybadger.wiki
159 ~/scbc-2011/wiki$ svn commit -m "a log message"
161 Deleting hacker-poke/data/myPic.png Committed revision 87.
163 Making and Committing a Change
165 Now, recall the software-carpentry.org tutorial. You're Wolfman. The guy next
166 to you, he's Dracula. I'll be the Mummy. Please pick a random place in one of
167 the files and insert a comment, like an easter egg.
169 **********************************************************************************
170 Exercise : Making Changes
171 **********************************************************************************
173 Step 1 : Insert something
175 If you're not in the terminal, just open up the ReadMe.wiki file.
177 If you're new to the command line, you can open the best text editor like so:
182 ~/scbc-2011/wiki$ vi ReadMe.wiki
184 Once it's open, you'll see some text. Just type the letter 'i' and place a line
185 anywhere you like. The line is a comment if it begins with a pound sign #, like
190 #summary A Readme for the Repository
194 ==Software Dependencies==
195 * Python 2.71 (or greater?)
203 To save it, press 'ESC', then ':wq' .
205 Step 2 : Check the status of your local copy
207 Now that you've changed a file, let's see what SVN thinks about your local
212 ~/scbc-2011$ svn status
218 If you want, try committing your change. If it's a comment, it won't break
219 anything. If you think someone else has committed recently, don't forget to
224 ~/scbc-2011$ svn update
228 If SVN lets you know that someone else has committed changes to the same file
229 recently, hang on and watch until the next section on conflicts. If svn doesn't
236 ~/scbc-2011$ svn commit -m "The m flag indicates that you'd like to leave a log \
237 message saying what you've done. Here, we each added a comment."
239 The m flag allows you to add a comment that will be stored in the repository to
240 help your collaborators keep track of the changes.
242 ----------------------------------------------------------------------------------
244 ----------------------------------------------------------------------------------
246 Some of you may have received an error message about a conflict.
248 **********************************************************************************
249 Exercise: Resolving Conflicts
250 **********************************************************************************
252 Step 1 : Update Before Committing
260 Conflict discovered in 'ReadMe.wiki'.
262 Select: (p) postpone, (df) diff-full, (e) edit, (h) help for more options:
267 The options are many :
271 (p) postpone - mark the conflict to be resolved later (df) diff-full - show
272 all changes made to merged file (e) edit - change merged file in an editor (r)
273 resolved - accept merged version of file (mf) mine-full - accept my version of
274 entire file (ignore their changes) (tf) theirs-full - accept their version of
275 entire file (lose my changes) (l) launch - launch external tool to resolve
276 conflict (h) help - show this list For now, you want to do some analysis, so
281 Step 3 : Check the Differences
283 Try diff (or meld if you have it).
287 $ diff myfile1.py myfile2.py Step 4 : Resolve the Conflict
289 The svn command resolve in combination with --accept and one of the choices
290 from before will automatically delete the right files. Alternatively, you could
291 delete all of the files that you don't like, move the correct one to the right
292 filename, and try committing again. For now, we'll do it the clean way. For
293 example, pretend you'd like to accept yours rather than the other.
297 $ svn resolve --accept ReadMe.wiki.mine Resolved conflicted state of
300 Importantly, if you decide to neglect all of your changes instead, you can
301 choose to revert. Try svn help revert to find out how to do that.
305 $ svn revert ReadMe.wiki
309 ----------------------------------------------------------------------------------
311 ----------------------------------------------------------------------------------
313 Okay Wolfmen, open up KatyHuff.wiki and replace my name with your own (or
314 someone else's, in case you're shy).
316 Now, clearly we've all just tried to change the same thing at once. The first
317 one of us to update and commit will have no problems. However, when the rest of
318 us try, SVN won't let us merge our changes. We have to talk this one over and
319 decide who gets to commit. The rest of us will have to resolve conflicts as we