Dealing with Conflicting Updates in Git 0.6 Dealing wit… · Synchronizing with the server (1)...

16
Dealing with Conflicting Updates in Git CS 5010 Program Design Paradigms “Bootcamp” Lesson 0.6 © Mitchell Wand, 2012-2014 This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. 1

Transcript of Dealing with Conflicting Updates in Git 0.6 Dealing wit… · Synchronizing with the server (1)...

Page 1: Dealing with Conflicting Updates in Git 0.6 Dealing wit… · Synchronizing with the server (1) my-project docs manual.docx user_docs.docx src main.rkt module1.rkt module2.rkt module3.rkt.git

DealingwithConflictingUpdatesinGit

CS5010ProgramDesignParadigms“Bootcamp”Lesson0.6

©MitchellWand,2012-2014ThisworkislicensedunderaCreative Commons Attribution-NonCommercial 4.0 International License. 1

Page 2: Dealing with Conflicting Updates in Git 0.6 Dealing wit… · Synchronizing with the server (1) my-project docs manual.docx user_docs.docx src main.rkt module1.rkt module2.rkt module3.rkt.git

LearningObjectives

• Attheendofthislessonyoushouldbeableto:– explainwhathappenswhenyoupullchangesfromanupstreamrepository

– understandwhataconflictis– resolveasimplemergeconflictinatextfile(includinga.rkt file)

2

Page 3: Dealing with Conflicting Updates in Git 0.6 Dealing wit… · Synchronizing with the server (1) my-project docs manual.docx user_docs.docx src main.rkt module1.rkt module2.rkt module3.rkt.git

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

Page 4: Dealing with Conflicting Updates in Git 0.6 Dealing wit… · Synchronizing with the server (1) my-project docs manual.docx user_docs.docx src main.rkt module1.rkt module2.rkt module3.rkt.git

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

Page 5: Dealing with Conflicting Updates in Git 0.6 Dealing wit… · Synchronizing with the server (1) my-project docs manual.docx user_docs.docx src main.rkt module1.rkt module2.rkt module3.rkt.git

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

Page 6: Dealing with Conflicting Updates in Git 0.6 Dealing wit… · Synchronizing with the server (1) my-project docs manual.docx user_docs.docx src main.rkt module1.rkt module2.rkt module3.rkt.git

Q:Whenmightyouneedtomerge?

A:Whenyourpartnercommittedsomechangestotheserver,whichyoudon'thave.

Yourpartner'swork(onthe

server)

Yourwork(onyourlocalmachine)

Yourlastpull

6

Page 7: Dealing with Conflicting Updates in Git 0.6 Dealing wit… · Synchronizing with the server (1) my-project docs manual.docx user_docs.docx src main.rkt module1.rkt module2.rkt module3.rkt.git

ResultofSyncing

Yourpartner'swork(onthe

server)

Yourwork(onyourlocalmachine)

Yourchangesareappliedtothelatestversionontheserver.Thisiscalled"rebasing"

Combinedworknowlivesonboththeserverandyourlocalmachine.

7

Page 8: Dealing with Conflicting Updates in Git 0.6 Dealing wit… · Synchronizing with the server (1) my-project docs manual.docx user_docs.docx src main.rkt module1.rkt module2.rkt module3.rkt.git

Mostofthetime,thisworkswell

• Solongasyouandyourpartnerareworkingonseparatepartsofthefile,thisworksfine.

• Bothsetsofchangesgetmade,andthehistoryontheserverstayslinear

• Butwhathappensifyouandyourpartnercommitincompatiblechanges?

8

Page 9: Dealing with Conflicting Updates in Git 0.6 Dealing wit… · Synchronizing with the server (1) my-project docs manual.docx user_docs.docx src main.rkt module1.rkt module2.rkt module3.rkt.git

Here'swhatyou'llsee

9

Page 10: Dealing with Conflicting Updates in Git 0.6 Dealing wit… · Synchronizing with the server (1) my-project docs manual.docx user_docs.docx src main.rkt module1.rkt module2.rkt module3.rkt.git

So,clickontoolsandopenashell

Don'tpanic!First,lookatthefilein

aneditor

Here'swhatwe'regoing to

do

10

Page 11: Dealing with Conflicting Updates in Git 0.6 Dealing wit… · Synchronizing with the server (1) my-project docs manual.docx user_docs.docx src main.rkt module1.rkt module2.rkt module3.rkt.git

Here'swhatthe

conflictedfilelookslike(inemacs)

what'sontheserver

what'sonthelocalmachine

11

Page 12: Dealing with Conflicting Updates in Git 0.6 Dealing wit… · Synchronizing with the server (1) my-project docs manual.docx user_docs.docx src main.rkt module1.rkt module2.rkt module3.rkt.git

Next:editthefilethewayyouwantit

nomore>>>'s

12

Page 13: Dealing with Conflicting Updates in Git 0.6 Dealing wit… · Synchronizing with the server (1) my-project docs manual.docx user_docs.docx src main.rkt module1.rkt module2.rkt module3.rkt.git

addthefixed-upfiletothecommit

tellgit tocontinue tothenextchange

ok!wearereadytosync

ifthereweremoreconflicts,we'dhavetodothisprocess

foreachofthem. 13

Page 14: Dealing with Conflicting Updates in Git 0.6 Dealing wit… · Synchronizing with the server (1) my-project docs manual.docx user_docs.docx src main.rkt module1.rkt module2.rkt module3.rkt.git

Andwe'rereadytogetbacktowork

Observethatbothcommitsarenowin

yourhistory

14

Page 15: Dealing with Conflicting Updates in Git 0.6 Dealing wit… · Synchronizing with the server (1) my-project docs manual.docx user_docs.docx src main.rkt module1.rkt module2.rkt module3.rkt.git

Isthisapain?• Yes,butitshouldn'thappentoooften.• Yourinteractionwiththeshellmightlooksomewhatdifferent.

• Buttheworkflowisthesame:– identifythefilesthatareconflicted– identifyandresolvetheconflictsineachfile

• theconflictedregionwillbemarkedwith>>>'s.• Useyourfavoritetexteditorforthis.

– Whenyougetthefilethewayyouwantit,addittoyourcommit.

– Commitallthefixed-upfiles.

15

Page 16: Dealing with Conflicting Updates in Git 0.6 Dealing wit… · Synchronizing with the server (1) my-project docs manual.docx user_docs.docx src main.rkt module1.rkt module2.rkt module3.rkt.git

Summary

• Inthislessonyouhavelearned– whathappenswhenyoupullchangesfromanupstreamrepository

– whataconflictis– howtoresolveasimplemergeconflictinatextfile(includinga.rkt file)

16