ìComputerSystemsandNetworksECPE170–JeffShafer–UniversityofthePacific
VersionControl
LabSchedule
ì Todayì Lab2–VersionControl
ì NextWeekì IntrotoC(forC++programmers)ì Lab3–CProgramming/BuildTools
ì Deadlinesì Lab1Report–Jan25h,2020by5am
ì SubmitviaCanvasì Lab2Report–Jan28th,2020by5am
ì Submitviaversioncontrol
Spring2020ComputerSystemsandNetworks
2
BeforeVersionControl
1. <Report.doc>
2. <Report.doc.bak>
3. <Report-1.doc>
4. Emailofftopartner…
5. <Report-2.doc>
6. Partnerrespondswithdoc(thatismissingthechangesyoujustmade)
7. <Report-2a.doc>
8. <Report-2a-WITH-REFERENCES.doc>
9. Emailofftopartner…Partnerrespondswithnewdoc<Report-3.doc>
10. <Report-3-FINAL.doc>
11. <Report-3-FINAL-OOPS-FIXED-TYPO-FINAL.doc>
ComputerSystemsandNetworks
3
Spring2020
VersionControlFeatures
ì Projecthistorytracking
ì Concurrentfileediting(merges)
ì Non-linearprogramhistory(branches)
ì Namingschemeforprogramreleases(tags)
ComputerSystemsandNetworks
4
Spring2020
MotivationforVersionControl
ì Whywouldasingleprogrammer(workingalone)useversioncontrol?ì Backupfilesì Roll-backtoearlier(working)versionì Seechangesmadebetweencurrent(broken)code
andearlier(working)codeì Maintainmultipleversionsofasingleproductì Experimentwithanewfeature
ì Tryariskychangeina“sandbox”ì Ifitworks,youcanmergeitintotheregularcode.
Ifitfails,youcanthrowitaway.
ComputerSystemsandNetworks
5
Spring2020
MotivationforVersionControl
ì Whywouldasmallgroupofdevelopersuseversioncontrol?ì Allthereasonsasingleprogrammerwould,plus…ì Mergingdifferentchangesmadebydifferent
developersintothesamefileì Addanewfunctionatthebottom?Safeto
automaticallymergeinì Re-writeafunctionatthesametimeanother
developerisalsoeditingit?Versioncontrolwillcatchthisandaskyoutodecidewhicheditsshould“win”
ì Blame–whowrotethisbuggycode?!?
ComputerSystemsandNetworks
6
Spring2020
MotivationforVersionControl
ì Whywouldalargegroupofdevelopersuseversioncontrol?
ì Differentquestion:CouldyoudeveloptheLinuxkernel,AdobePhotoshop,GoogleChrome,etc…using:ì Asingleshared“folderofcode”?ì Emailingcodesnippetsbetweendevelopers?ì Everyonesitsaroundandsharesonekeyboard?
ComputerSystemsandNetworks
7
Spring2020
VersionControlBasics
ì WhatkindoffilesshouldIkeepinversioncontrol?ì Programsourcecode(obviously)ì VHDL/Verilogfiles(fromdigitaldesignclass)ì Matlabscriptsì HTMLfilesì Serverconfigurationfiles
ì ImagineyouworkatLivermoreNationalLabs,andyourjobistomanageLinuxclustercomputerswith100,000+machines(nodes)…
ì Anythingthatisplaintext!
ComputerSystemsandNetworks
8
Spring2020
VersionControlBasics
ì WhatkindoffilesshouldInotkeepinversioncontrol?
ComputerSystemsandNetworks
9
https://www.youtube.com/watch?v=WJVBvvS57j0 Spring2020
VersionControlBasics
ì WhatkindoffilesshouldInotkeepinversioncontrol?ì Thesearemorewhatyou’dcall“guidelines”thanactual
“rules”…ì Binarydata
ì Howdoyoumergetwodifferentbinaryfilestogether?Nogeneral-purposewaytodothis
ì Anythingauto-generatedbythecompilerì Objectfilesorexecutablefileì Wastesspaceonuselessjunkthatcanbere-created
automaticallyì Texteditortempfiles(e.g.main.c~)
ComputerSystemsandNetworks
10
Spring2020
VersionControlBasics
ì Bigriskinputtingtheexecutableinversioncontrolì Ifyouforgettocompilebeforeacommit,the
executablemaynotbeinsyncwiththeattachedsourcecode!
ì Bigheadacheifyoueverrollbacktothisversion!
ì InECPE170,allourexecutablefilescanbeproducedinunder5secondswithonecommand.There’snoneedtoincludetheminyourrepository
ComputerSystemsandNetworks
11
Spring2020
Problem1–Comparison
ì HowaretheseVersionControlSystemsdifferent?ì Gitì Mercurialì SVN
ComputerSystemsandNetworks
12
P1
Spring2020
DistributedVersionControl
ì WhydotheycallGitadistributedversioncontrolsystem?ì Conventionalsystems(e.g.,Subversionor“svn”)
haveacentralizedserverholdthe“master”copyì Distributedversioncontrol–eachcopyisitsown
full-fledgedmaster!(Butyoucanstillpushchangesfromoneperson’scopytoanother)ì Allowsversioncontroltoworkofflineì Allowsversioncontroltoworkwithad-hocgroups
ComputerSystemsandNetworks
13
Spring2020
Universe1:CentralizedVersionControl(SVN)
CentralizedRepository
svncommit
Ivan’sDir Lisa’sDir Kevin’sDir Dorothy’sDir
Universe2:DistributedVersionControl(Git)CentralizedRepository
gitcommit
Ivan’sDir Lisa’sDir Kevin’sDir Dorothy’sDir
Ivan’sRepo Lisa’sRepo Kevin’sRepo Dorothy’sRepo
gitpush
gitpull
GitCommandFlow(usually)
1. git clone <repositoryaddress>a. #getrepoonyourdesktop
2. git add <filenames>#alwaysspecifyafilenametoadda. #addnewfilesandmakechanges
3. git commit -m <meaningfulcommitmessage>a. #committoyourrepo.Alsouse–atocommitchangedfilesb. Makechangesandrepeat3
4. git push #All done? Let everyone see
MercurialCommandFlow(Typical)1. hg clone <repositoryaddress>
a. #getrepoonyourdesktop
2. hg add <filenames>#alwaysspecifyafilenametoadda. #addnewfilesandmakechanges
3. hg commit -m <meaningfulcommitmessage>a. #committoyourrepob. Makechangesandrepeat3
4. hg revert –alla. #ifnothappywithchanges,reverttolastcommit(do4)b. Then make changes and go to 3
5. hg push #All done? Let everyone see
Problem2–GitCheatSheet
ì GofindaGitcheatsheet(or2)forfuturereference
ComputerSystemsandNetworks
18
P2
Spring2020
VersionControlinECPE170
ì Versioncontrolrequiredforthisclassì Usedtodistributeboilerplatecodeforlabsì Usedtoturninassignmentswhenfinished
ComputerSystemsandNetworks
19
Spring2020
VersionControlinECPE170
ì Ifyouonlydoonecheck-inattheveryendofyourproject,you'vemissedthewholepointofversioncontrol,andturnedavaluabletoolintoanobstacletocompletingtheassignment
ì Check-incodeonaregularbasis!
ComputerSystemsandNetworks
20
Spring2020
ComputerSystemsandNetworks
21
Spring2020
ComputerSystemsandNetworks
22
http://xkcd.com/1597/
"Ifthatdoesn'tfixit,git.txtcontainsthephonenumberofafriendofminewhounderstandsgit.Justwaitthroughafewminutesof'It'sreallyprettysimple,justthinkofbranchesas...'andeventuallyyou'lllearnthecommandsthatwillfixeverything.”
Spring2020
Problem3–MultipleHeads
ì Researchandanswerquestion3onyourown,andthenbeginthelab!
ComputerSystemsandNetworks
23
P3
Spring2020