DealingwithConflictingUpdatesinGit
CS5010ProgramDesignParadigms“Bootcamp”Lesson0.6
©MitchellWand,2012-2014ThisworkislicensedunderaCreative Commons Attribution-NonCommercial 4.0 International License. 1
LearningObjectives
• Attheendofthislessonyoushouldbeableto:– explainwhathappenswhenyoupullchangesfromanupstreamrepository
– understandwhataconflictis– resolveasimplemergeconflictinatextfile(includinga.rkt file)
2
ACommit
my-project docs manual.docx
user_docs.docx
srcmain.rkt
module1.rkt
module2.rkt
module3.rkt
.git
commit
Whenyoudoa“commit”,yourecordallyourlocalchangesintothemini-fs.
Themini-fs is“append-only”.Nothing iseverover-writtenthere,soeverythingyouevercommitcanberecovered.
Rememberthebasicstoryfromthepreceding
lesson
3
Synchronizingwiththeserver(1)
my-project docs manual.docx
user_docs.docx
srcmain.rkt
module1.rkt
module2.rkt
module3.rkt
.git push
Attheendofeachworksession,youneedtosaveyourchangesontheserver.Thisiscalleda“push”.
Nowallyourdataisbackedup.• Youcanretrieveit,onyourmachineor
someothermachine.• Wecanretrieveit(that’showwecollect
homework)
yourlocalmachine aserver,somewhereontheinternet,eg.github.com
4
Synchronizingwiththeserver(2)
my-project docs manual.docx
user_docs.docx
srcmain.rkt
module1.rkt
module2.rkt
module3.rkt
.git pull
Toretrieveyourdatafromtheserver,youdoa“pull”.A“pull”takesthedatafromtheserverandputsitboth inyour localmini-fsandinyourordinary files.
Ifyourlocalfilehaschanged,git willmergethechangesifpossible.Ifitcan’tfigureouthowtothemerge,youwillgetanerrormessage.Dealingwiththisisbeyond thescopeofthistutorialL
yourlocalmachine aserver,somewhereontheinternet,eg.github.com
pull
5
Q:Whenmightyouneedtomerge?
A:Whenyourpartnercommittedsomechangestotheserver,whichyoudon'thave.
Yourpartner'swork(onthe
server)
Yourwork(onyourlocalmachine)
Yourlastpull
6
ResultofSyncing
Yourpartner'swork(onthe
server)
Yourwork(onyourlocalmachine)
Yourchangesareappliedtothelatestversionontheserver.Thisiscalled"rebasing"
Combinedworknowlivesonboththeserverandyourlocalmachine.
7
Mostofthetime,thisworkswell
• Solongasyouandyourpartnerareworkingonseparatepartsofthefile,thisworksfine.
• Bothsetsofchangesgetmade,andthehistoryontheserverstayslinear
• Butwhathappensifyouandyourpartnercommitincompatiblechanges?
8
Here'swhatyou'llsee
9
So,clickontoolsandopenashell
Don'tpanic!First,lookatthefilein
aneditor
Here'swhatwe'regoing to
do
10
Here'swhatthe
conflictedfilelookslike(inemacs)
what'sontheserver
what'sonthelocalmachine
11
Next:editthefilethewayyouwantit
nomore>>>'s
12
addthefixed-upfiletothecommit
tellgit tocontinue tothenextchange
ok!wearereadytosync
ifthereweremoreconflicts,we'dhavetodothisprocess
foreachofthem. 13
Andwe'rereadytogetbacktowork
Observethatbothcommitsarenowin
yourhistory
14
Isthisapain?• Yes,butitshouldn'thappentoooften.• Yourinteractionwiththeshellmightlooksomewhatdifferent.
• Buttheworkflowisthesame:– identifythefilesthatareconflicted– identifyandresolvetheconflictsineachfile
• theconflictedregionwillbemarkedwith>>>'s.• Useyourfavoritetexteditorforthis.
– Whenyougetthefilethewayyouwantit,addittoyourcommit.
– Commitallthefixed-upfiles.
15
Summary
• Inthislessonyouhavelearned– whathappenswhenyoupullchangesfromanupstreamrepository
– whataconflictis– howtoresolveasimplemergeconflictinatextfile(includinga.rkt file)
16
Top Related