Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Incorporating Version Control into Programming Courses

Tommy MacWilliam
March 07, 2013
100

Incorporating Version Control into Programming Courses

Tommy MacWilliam

March 07, 2013
Tweet

Transcript

  1. Incorporating Version
    Control into Programming
    Courses
    Tommy MacWilliam
    [email protected]

    View Slide

  2. View Slide

  3. Source Control
    Management

    View Slide

  4. What?
    • track revisions of files
    • review past versions of projects
    • collaborate with peers and staff

    View Slide

  5. What?
    • CVS
    • SVN
    • Git
    • Mercurial
    • Bazaar
    • ...

    View Slide

  6. Students: Why?
    • “I need to work on a project with a
    partner”

    View Slide

  7. Students: Why?
    • “I need to work on a project with a
    partner”
    • “It was working a few hours ago, but I
    broke it”

    View Slide

  8. Students: Why?
    • “I need to work on a project with a
    partner”
    • “It was working a few hours ago, but I
    broke it”
    • “I want to back up my code so I can work
    on another machine”

    View Slide

  9. Staff: Why?
    • “I want to collect homework submissions
    on my server”

    View Slide

  10. Staff: Why?
    • “I want to collect homework submissions
    on my server”
    • “I want to allow students to review each
    others’ code”

    View Slide

  11. Staff: Why?
    • “I want to collect homework submissions
    on my server”
    • “I want to allow students to review each
    others’ code”
    • “I want to distribute updates to
    distribution code”

    View Slide

  12. Vocabulary
    • repository: project containing source code
    files
    • commit: snapshot of a project in time
    • log: history of commits for a project
    • branch: independent set of changes
    • remote: server hosting code
    • tag: human-readable name for a commit

    View Slide

  13. SCM Tools
    • centralized
    • all commits go to one repository
    • decentralized
    • commits go to developers’ individual
    repositories

    View Slide

  14. SVN

    View Slide

  15. SVN with Google Code

    View Slide

  16. View Slide

  17. svn checkout
    https://project.googlecode.com/svn/trunk/
    project --username [email protected]

    View Slide

  18. Generated Password

    View Slide

  19. https://code.google.com/hosting/settings

    View Slide

  20. Repository
    Conventions
    • trunk: source code
    • branches: independent sets of changes
    • tags: named commits

    View Slide

  21. svn add pset1.c

    View Slide

  22. svn rm pset1.c

    View Slide

  23. svn status

    View Slide

  24. svn commit -m “done!”

    View Slide

  25. svn update

    View Slide

  26. svn log

    View Slide

  27. Workflow
    • student creates and checks out repository
    • student adds, commits files to repository
    • staff updates from repository to view files

    View Slide

  28. Basic SVN Workflow
    • create repository
    • svn checkout
    https://project.googlecode.com/svn/
    • edit pset1.c
    • svn add pset1.c
    • svn commit -m “done!”

    View Slide

  29. Practice!
    • create a new SVN repository called
    yourname-sigcse
    • checkout the repository to ~/svn/student1
    • create a file called pset1.c
    • add and commit pset1.c to the pset1 repo
    • add and commit test.c to the pset1 repo
    • view the history of commits

    View Slide

  30. svn diff

    View Slide

  31. svn diff -r 1:2

    View Slide

  32. Practice!
    • make changes to pset1.c without
    committing, then view the changes
    • commit the changes and compare to
    previous revision
    • compare the last revision to the first
    revision
    • search all commit logs for the word “done”

    View Slide

  33. svn checkout -r 123

    View Slide

  34. svn update -r 123

    View Slide

  35. Practice!
    • roll back to the first revision
    • check out a new copy of pset1, starting at
    the second revision

    View Slide

  36. SVN Collaboration
    • check out pset1 (again) to ~/svn/student2
    • make a change and commit as student2
    • update the repository as student1

    View Slide

  37. Alice
    svnadmin create pset1
    Bob

    View Slide

  38. Alice
    svn co https://host/pset1
    Bob

    View Slide

  39. Alice
    svn co https://host/pset1
    Bob

    View Slide

  40. Alice
    svn co https://host/pset1
    Bob

    View Slide

  41. Alice
    svn co https://host/pset1
    Bob

    View Slide

  42. Alice
    svn commit -m “done”
    Bob

    View Slide

  43. Alice
    svn commit -m “done”
    Bob

    View Slide

  44. Alice
    svn up
    Bob

    View Slide

  45. Alice
    svn up
    Bob

    View Slide

  46. Merge Conflicts
    • students commit incompatible changes
    • cannot commit until conflicts are resolved

    View Slide

  47. Creating a Merge
    Conflict
    • student1 edits pset1.c to say “here comes a
    conflict”
    • student1 commits to pset1 repo
    • student2 edits pset1.c to say “I don’t like
    conflict”
    • student2 tries to commit

    View Slide

  48. Conflict discovered in '~/svn/student2/pset1/file.c'.
    Select: (p) postpone, (df) diff-full, (e) edit,
    (mc) mine-conflict, (tc) theirs-conflict,
    (s) show all options: d

    View Slide

  49. Resolving a Merge
    Conflict
    • don’t panic!
    • mc: keep my changes to the file
    • tc: keep their changes to the file
    • e: manually edit conflicted file
    • p: view files that caused conflict separately

    View Slide

  50. <<<<<<<
    this is student1
    =======
    this is student2
    >>>>>>>
    Single File Resolution

    View Slide

  51. [email protected] (~/svn/student2/pset1): ls
    file.c file.c.mine file.c.r3
    Multiple File Resolution

    View Slide

  52. Resolving a Merge
    Conflict
    • don’t panic!

    View Slide

  53. Practice!
    • edit student1/pset1.c to say “here comes a
    conflict”
    • commit from student1/pset1
    • edit student2/pset1.c to say “I don’t like conflict”
    • commit from student2/pset1
    • press “e” to edit as a single file
    • repeat, but press “p” to resolve conflict!

    View Slide

  54. Tags
    • human-readable aliases for commits
    • software releases, betas, submissions

    View Slide

  55. svn cp
    https://project.googlecode.com/svn/trunk/
    https://project.googlecode.com/svn/tags/1.0

    View Slide

  56. Branches

    View Slide

  57. Branches
    • one partner wants to try something out

    View Slide

  58. Branches
    • one partner wants to try something out
    • develop a feature independently of project

    View Slide

  59. Branches
    • one partner wants to try something out
    • develop a feature independently of project
    • staff make changes during feedback process

    View Slide

  60. svn cp
    https://project.googlecode.com/svn/trunk/
    https://project.googlecode.com/svn/branches/test

    View Slide

  61. Branches
    • independent sets of changes
    • changes on one branch don’t affect other
    branches
    • switching between branches changes
    working copy

    View Slide

  62. svn switch
    https://project.googlecode.com/svn/branches/test

    View Slide

  63. svn rm
    https://project.googlecode.com/svn/branches/test

    View Slide

  64. Practice!
    • create a branch called “test”
    • switch to the branch
    • make changes and commit
    • switch back to trunk
    • delete branch “test”

    View Slide

  65. SVN on GitHub

    View Slide

  66. SVN on GitHub
    • svn co --depth empty
    https://github.com/you/project
    • svn up trunk
    • edit files, svn add, svn commit

    View Slide

  67. Git

    View Slide

  68. git config --global user.name
    “Tommy MacWilliam”

    View Slide

  69. git config --global user.email
    [email protected]

    View Slide

  70. git init

    View Slide

  71. git add pset1.c

    View Slide

  72. git add --all

    View Slide

  73. git status

    View Slide

  74. git commit -m “done!”

    View Slide

  75. git log

    View Slide

  76. 5aeebab117b892fa42002146e4c62be676bc4621
    b43b0ad1e8108e7ab870d7a54feac93ae8b8600e
    461476587780aa9fa5611ea6dc3912c146a91760
    Commit
    ID

    View Slide

  77. 5aeebab117b892fa42002146e4c62be676bc4621
    b43b0ad1e8108e7ab870d7a54feac93ae8b8600e
    461476587780aa9fa5611ea6dc3912c146a91760
    Commit
    ID
    HEAD

    View Slide

  78. Practice!
    • create a new repository in ~/git/pset1
    • create a file called pset1.c
    • add and commit pset1.c
    • make more changes to pset1.c
    • add and commit pset1.c again

    View Slide

  79. Git on GitHub

    View Slide

  80. SSH Keys

    View Slide

  81. ssh-keygen

    View Slide

  82. View Slide

  83. git clone
    [email protected]:you/project

    View Slide

  84. git remote

    View Slide

  85. git remote add origin url

    View Slide

  86. git push origin master

    View Slide

  87. Basic Git Workflow
    • staff (or students) create remote
    repositories
    • students
    • clone repository
    • add and commit changes
    • push changes to remote repository

    View Slide

  88. Practice!
    • create a GitHub repository
    • clone the repository
    • create pset1.c, then add and commit it
    • push pset1.c to the remote repository

    View Slide

  89. git show

    View Slide

  90. git show b43b0

    View Slide

  91. git diff HEAD

    View Slide

  92. git diff b43b0 5aeeb

    View Slide

  93. Practice!
    • make changes to pset1.c without
    committing, then view the changes
    • commit the changes and compare to
    previous revision
    • compare the last revision to the first
    revision
    • search all commit logs for the word “done”

    View Slide

  94. git checkout b43b0

    View Slide

  95. git checkout b43b0
    pset1.c

    View Slide

  96. git checkout master

    View Slide

  97. git reset --hard

    View Slide

  98. Practice!
    • roll back to the first revision
    • roll only one file back to the second
    revision
    • fast-forward to the current state again

    View Slide

  99. git revert b43b0

    View Slide

  100. 5aeeb
    b43b0
    46147

    View Slide

  101. 5aeeb
    b43b0
    46147
    a45bc
    git revert 46147

    View Slide

  102. Practice!
    • undo the changes in your last commit
    • undo the commit that undoes that commit

    View Slide

  103. git tag done

    View Slide

  104. git push --tags

    View Slide

  105. git tag

    View Slide

  106. git tag -l “1.*”

    View Slide

  107. Practice!
    • create a tag called “1.0”
    • commit new changes
    • create a tag called “1.1”
    • view tags

    View Slide

  108. git branch

    View Slide

  109. git branch test

    View Slide

  110. git checkout test

    View Slide

  111. 5aeeb
    b43b0
    46147
    master

    View Slide

  112. 5aeeb
    b43b0
    46147
    master
    f862f
    36223
    test
    git branch test

    View Slide

  113. git checkout master

    View Slide

  114. git merge

    View Slide

  115. 5aeeb
    b43b0
    46147
    f862f
    36223
    git branch test
    a34bc
    git merge test

    View Slide

  116. git branch -D test

    View Slide

  117. Practice!
    • create a branch called “test”
    • switch to the test branch
    • make and commit changes
    • switch to the master branch
    • merge changes from the test branch
    • delete the test branch

    View Slide

  118. 5aeeb
    b43b0
    46147
    f862f
    36223
    master test
    git branch test

    View Slide

  119. 5aeeb
    b43b0
    46147 f862f 36223
    master
    git rebase

    View Slide

  120. Practice!
    • create a branch called “test2”
    • switch to the test2 branch
    • make and commit changes
    • switch to the master branch
    • rebase changes from the test2 branch
    • delete the test2 branch

    View Slide

  121. Collaborating with Git
    • students have their own local repositories
    • students commit, branch, etc. on local
    repositories
    • students push to and pull from a shared
    repository

    View Slide

  122. git pull origin master

    View Slide

  123. git pull --rebase

    View Slide

  124. Alice Bob
    git init
    git add --all
    git commit

    View Slide

  125. Alice
    git remote add origin url
    git push origin master
    Bob

    View Slide

  126. Alice
    git remote add origin url
    git push origin master
    Bob

    View Slide

  127. Alice
    git clone url
    Bob

    View Slide

  128. Alice
    git clone url
    Bob

    View Slide

  129. Alice
    git add --all
    git commit
    Bob

    View Slide

  130. Alice
    git push origin master
    Bob

    View Slide

  131. Alice Bob
    git push origin master

    View Slide

  132. Alice
    git pull origin master
    Bob

    View Slide

  133. Alice Bob
    git pull origin master

    View Slide

  134. Practice!
    • create a pset2 repository on GitHub
    • clone the repository in ~/git/student1/pset2
    • add, commit, and push a change
    • clone the repository in ~/git/student2/pset2
    • add, commit, and push a change
    • pull the change from ~/git/student1/pset2

    View Slide

  135. Merge Conflicts
    • don’t panic!
    • git status shows conflicted files
    • git add files to resolve conflicts

    View Slide

  136. Resolving Conflicts
    <<<<<<<
    this is from test
    =======
    this is from master
    >>>>>>>

    View Slide

  137. Creating a Merge Conflict
    • student1 edits pset2.c to say “here comes a conflict”
    • student1 commits and pushes to pset2 repo
    • student2 edits pset2.c to say “I don’t like conflict”
    • student2 commits, tries to push

    View Slide

  138. Resolving using Merge
    • fix conflicts
    • git add --all
    • git commit -m “merge”

    View Slide

  139. Resolving using Rebase
    • fix conflicts
    • git add --all
    • git rebase --continue

    View Slide

  140. Git on BitBucket

    View Slide

  141. Using SCM in
    Programming Courses

    View Slide

  142. Using Google Code
    • each student creates repository for each
    project
    • students add staff as collaborators

    View Slide

  143. View Slide

  144. Using GitHub
    • https://github.com/edu
    • each student creates repository for each
    project
    • students add staff as collaborators

    View Slide

  145. View Slide

  146. Using BitBucket
    • unlimited free private repositories!
    • same process as GitHub

    View Slide

  147. Hosting SVN
    • svnadmin create --fs-type fsfs pset1
    • repo/conf/svnserve.conf
    • svnserve

    View Slide

  148. Hosting Git
    • https://github.com/sitaramc/gitolite
    • http://scie.nti.st/2007/11/14/hosting-git-
    repositories-the-easy-and-secure-way/

    View Slide

  149. Repository-Based
    • each project is a separate repository
    • students collaborate on same hosted
    repository
    • if projects are totally separate, makes sense
    • if projects build on each other, makes less
    sense

    View Slide

  150. Branch-Based
    • each student creates one repository for the
    course
    • each project is a different branch
    • if projects build on each other, makes sense
    • if projects are totally separate, makes less
    sense

    View Slide

  151. Distributing Code
    • each student:
    • create repository on GitHub
    • git clone git://github.com/course/pset1.git
    • git remote rm origin
    • git remote add origin [email protected]/student/
    pset1.git
    • git remote add distro git://github.com/course/
    pset1.git

    View Slide

  152. Submitting Code
    • students
    • git tag submission
    • git push --tags
    • staff
    • git checkout submission

    View Slide

  153. When Disaster Strikes
    • svn revert --recursive .
    • git reset --hard

    View Slide

  154. When Disaster Really
    Strikes
    • rm -rf .git
    • find . -type d -name .svn -exec rm -rf {} \;

    View Slide

  155. Potential Pitfalls
    • merge conflicts prevent pushes!
    • don’t panic
    • one minute before the deadline, still don’t
    panic
    • distinguish between submission and version
    control?
    • have a backup submission plan!

    View Slide

  156. Potential Pitfalls
    • commit timestamps are set by the client!
    • tags can be deleted and moved around
    • if new to SCM, submission process is very
    complicated
    • if using SCM, then teach SCM

    View Slide

  157. Hooks
    • small scripts that are triggered by SCM
    events
    • post-receive: whenever a push is received

    View Slide

  158. Automating Processes
    • http://developer.github.com/v3/
    • https://confluence.atlassian.com/display/
    BITBUCKET/Using+the+Bitbucket+REST
    +APIs

    View Slide

  159. version50

    View Slide

  160. gem install version50

    View Slide

  161. v50 create

    View Slide

  162. v50 status

    View Slide

  163. v50 save

    View Slide

  164. v50 history

    View Slide

  165. v50 warp

    View Slide

  166. v50 recover

    View Slide

  167. v50 download

    View Slide

  168. speakerdeck.com/tmacwill

    View Slide

  169. Incorporating Version
    Control into Programming
    Courses
    Tommy MacWilliam
    [email protected]

    View Slide