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

Incorporating Version Control into Programming Courses

Tommy MacWilliam
March 07, 2013
110

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 full-size slide

  2. Source Control
    Management

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size 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”
    • “I want to back up my code so I can work
    on another machine”

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  10. 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 full-size slide

  11. 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 full-size slide

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

    View full-size slide

  13. SVN with Google Code

    View full-size slide

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

    View full-size slide

  15. Generated Password

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  18. svn add pset1.c

    View full-size slide

  19. svn rm pset1.c

    View full-size slide

  20. svn commit -m “done!”

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  23. 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 full-size slide

  24. svn diff -r 1:2

    View full-size slide

  25. 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 full-size slide

  26. svn checkout -r 123

    View full-size slide

  27. svn update -r 123

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  30. Alice
    svnadmin create pset1
    Bob

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  35. Alice
    svn commit -m “done”
    Bob

    View full-size slide

  36. Alice
    svn commit -m “done”
    Bob

    View full-size slide

  37. Alice
    svn up
    Bob

    View full-size slide

  38. Alice
    svn up
    Bob

    View full-size slide

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

    View full-size slide

  40. 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 full-size slide

  41. 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 full-size slide

  42. 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 full-size slide

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

    View full-size slide

  44. jharvard@appliance (~/svn/student2/pset1): ls
    file.c file.c.mine file.c.r3
    Multiple File Resolution

    View full-size slide

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

    View full-size slide

  46. 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 full-size slide

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

    View full-size slide

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

    View full-size slide

  49. Branches
    • one partner wants to try something out

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  57. SVN on GitHub

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  61. git add pset1.c

    View full-size slide

  62. git add --all

    View full-size slide

  63. git commit -m “done!”

    View full-size slide

  64. 5aeebab117b892fa42002146e4c62be676bc4621
    b43b0ad1e8108e7ab870d7a54feac93ae8b8600e
    461476587780aa9fa5611ea6dc3912c146a91760
    Commit
    ID

    View full-size slide

  65. 5aeebab117b892fa42002146e4c62be676bc4621
    b43b0ad1e8108e7ab870d7a54feac93ae8b8600e
    461476587780aa9fa5611ea6dc3912c146a91760
    Commit
    ID
    HEAD

    View full-size slide

  66. 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 full-size slide

  67. Git on GitHub

    View full-size slide

  68. git remote add origin url

    View full-size slide

  69. git push origin master

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  72. git show b43b0

    View full-size slide

  73. git diff HEAD

    View full-size slide

  74. git diff b43b0 5aeeb

    View full-size slide

  75. 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 full-size slide

  76. git checkout b43b0

    View full-size slide

  77. git checkout b43b0
    pset1.c

    View full-size slide

  78. git checkout master

    View full-size slide

  79. git reset --hard

    View full-size slide

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

    View full-size slide

  81. git revert b43b0

    View full-size slide

  82. 5aeeb
    b43b0
    46147

    View full-size slide

  83. 5aeeb
    b43b0
    46147
    a45bc
    git revert 46147

    View full-size slide

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

    View full-size slide

  85. git tag done

    View full-size slide

  86. git push --tags

    View full-size slide

  87. git tag -l “1.*”

    View full-size slide

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

    View full-size slide

  89. git branch test

    View full-size slide

  90. git checkout test

    View full-size slide

  91. 5aeeb
    b43b0
    46147
    master

    View full-size slide

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

    View full-size slide

  93. git checkout master

    View full-size slide

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

    View full-size slide

  95. git branch -D test

    View full-size slide

  96. 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 full-size slide

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

    View full-size slide

  98. 5aeeb
    b43b0
    46147 f862f 36223
    master
    git rebase

    View full-size slide

  99. 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 full-size slide

  100. 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 full-size slide

  101. git pull origin master

    View full-size slide

  102. git pull --rebase

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  106. Alice
    git clone url
    Bob

    View full-size slide

  107. Alice
    git clone url
    Bob

    View full-size slide

  108. Alice
    git add --all
    git commit
    Bob

    View full-size slide

  109. Alice
    git push origin master
    Bob

    View full-size slide

  110. Alice Bob
    git push origin master

    View full-size slide

  111. Alice
    git pull origin master
    Bob

    View full-size slide

  112. Alice Bob
    git pull origin master

    View full-size slide

  113. 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 full-size slide

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

    View full-size slide

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

    View full-size slide

  116. 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 full-size slide

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

    View full-size slide

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

    View full-size slide

  119. Git on BitBucket

    View full-size slide

  120. Using SCM in
    Programming Courses

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  126. 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 full-size slide

  127. 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 full-size slide

  128. 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 full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  132. 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 full-size slide

  133. 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 full-size slide

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

    View full-size slide

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

    View full-size slide

  136. gem install version50

    View full-size slide

  137. v50 download

    View full-size slide

  138. speakerdeck.com/tmacwill

    View full-size slide

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

    View full-size slide