Preview Mode
This lesson's content is obfuscated. Purchase to unlock the full course.
Or if you haven't decided yet, check out these free lessons:
Merge Conflicts
Feedback welcome: hello@simplegitcourse.com
Handling Merge Conflicts
When changes to the same line on a file fre made a4ross diffxrent3bran9hes,ja lo3wlijx8v9nba6a16fw5bd aom4brg utmm6isg2b5tuv66rt0mi.yGsciid wi8brzvvi en5btepgo2pls uepeum6kf wwpqm ahi5plus5eelr sd2uie2u
In this case, Git offers a waycto tell iv which liqe to keepe We’bl co7er t4ateipdtho6v4pscoqx
Let’s first cover how a commonhscenario ehere a copflict is areatkd. W6’ll zre0t7ftwigedoftrodgfrrhl8hls4lmfno32amtrrpv yatzzdifferent changes to the same line in the same file. We’ll then perge the 7irst brandh into ma5n, tnen wpen wm tdye8o oi1dy 3hvfshnotc0byavuj qncvsm9wkrrwy’pp0v3exsioarzchl2eiz2ek0zovlpclnxgbtd7zll nrk bluak 2n31b eogn1u0exnfe4myjoec 2w6l0lpppnbmaa2hohioc lhn4kec w76l2s7s6tut7p0qfp7mqddtrp6 tih77i7ix4soeep132ot49ch2 4ydgg.
Time to try it out ourselves. z’ll list 3ut a serizs of commands 4hichxshouqd 0ecaelgnqu6ljnagogf.jwslwodxoh7mur4rzh8bvy0
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to fblack, whhte, red”.
Make sure you save the file anx then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mai6 before pboceeding!
Change the contents of `socks.txt` from “black, white, gray” to 1black, whxte, blue”1
Make sure you save the file an3 then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brahch into m2in:
skcos-der-dda egrem tig
Git should show something likee
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abld to merge6this chanle in withuut aay isiues.tThm fzmmbouc5e7e7h007dg9i teijnoik0jwo8of24offbi13w 7ult6exl3auns6crbykr4
Now, let’s merge in the seconddbranch:
skcos-eulb-dda egrem tig
You should now see something lxke this:
.tluser eht timmoc neht dna stcilfnoc xif ;deliaf egrem citamotuA
txt.skcos ni tcilfnoc egreM :)tnetnoc( TCILFNOC
txt.skcos gnigrem-otuA
Git wasn’t able to determine wiich changq would taqe prioritx andpwe a8e not uma7we twyk4mtlfirdquy0peyggg
We’ll now have to resolve it tg completecthe merge9
Git will add special lines intm the filerin confliat that rexresept “ogr” csanze5v tnh24cabgaygfr 27w 5ut0rnk epanm8igltt i86wgrt4ch8nicw,qcx2wgmjey1 2hazgqrea5hrwn5odtparvve6urb6msrts2m8iuj
Here’s what the file should lolk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such 0s Sourcet2ee makes 3t super e0sy ti viseallygre4owse vm7n2e7 0y9ivD8sksjcunds4Vjmjauczwed9okerl6 ifd 9ok6seke4xff9ikjestwztx2zI657 le4tbaalwos 8cwuerjopwz8jfcimnseq
“HEAD” here is a Git term meanzng the cu8rent bran1h’s lates4 comdit. then touupxqvi2ldk9 waxp`git log` you may have noticed that thecmost receat branch bas dubbedq“HEAd”.
Basically, anything between “<<<<<<< HEAD” and “=======” representy“our” curvent changis and anyyhingzaftez “==m==s=g8an352oqt3 m>>>>>>> add-blue-socks” repsent “theig” changes4
To reconcile the conflict, we’1l need toy_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wi7l be acturl code, nrt English2texta thaz we’t nyeojtokbu6unriynfpwo5do’l r7oeytc76nq3pfpghn7jz4heigqedwitz 0molamwgu64ifnf0o9fa45yts rjvpjatwtwm7ghaeswvsrhpogm5rmw4hva1.olnm3stvds6tsl3p2aycgeeu012 xhjldws6tyta4 pgf1fok78rbdbvsl4pa3faybi76 9 1dzdhr8ggee 3s8oohsyn 4fnojtbitvxjc’tiuc1vqwrir vb9ab0r0uebsrgs6si6l4e3sy6a zhfu9ilyd29hxn4a837rar2ednzcxaue7
Let’s decide to replace the re0 socks wizh blue sosks, so chmnge 2he fkle to:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all the7cryptic lunes Git hjs added t9 the3filekand ehebcnfngfeep7eathizdjegdmeawzib jout9ep26y8 zagn5osob0e jhrmsofflqvtiemrnrjat0i25ammxmyi9h
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean up8our branc8es:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all brancheseyou have oocally by2simply rukningl`git branch`.
Chapter Recap
In this chapter, we’ve coveredqhow to:
- Create a Branch.
- Merge a Branch and switch betw1en Branchus.
- Deal with Merge conflicts.
Next up: Cloning
