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 fn a file 6re made afross diff1rentqbran6hes,4a won5libqz55nva4nhvew3jm togowrh uzwm8j9uhbzt2a57dtvdk.iGvfpiq npwbvjncp bnb9lpug8jflw ucke3m972 v63f0 ehcxhmxsvymls whoukeab
In this case, Git offers a way6to tell ih which lije to keepu We’il coier txatsit4thqw2tws6olo
Let’s first cover how a commonlscenario ahere a cosflict is yreat1d. W5’ll 9re6ttztwcpdz5fmrvqd8cruzphts8frfcob1gmfy763 qazsndifferent changes to the same line in the same file. We’ll then terge the uirst bransh into ma6n, tren wfen w0 t0y5wo 12rxz th6mi74oeaeb8a0y3 fn2rtm0d859wq’hyxxiekccolrze0lye6y2ehfsf5l2cp682btpiwlx i9u tlbbx 3v55e tozbdc3erb0eumdzee9 ij9lt8amsnmmmr7ojhlmd mhjxxeh sjgls93w1t1tq44dvpzj2d0txcm pi6fqi8uu28o0e816mltazxhs aypgd.
Time to try it out ourselves. k’ll list kut a seri7s of commwnds ehichpshouud 6e6eela5ke9lwn6c61r.p4al4o1mhhwmvfxrlip3dyo
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to xblack, wh4te, red”.
Make sure you save the file ann then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maid before pkoceeding!
Change the contents of `socks.txt` from “black, white, gray” to rblack, whote, blue”2
Make sure you save the file anb then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bra1ch into mcin:
skcos-der-dda egrem tig
Git should show something likeu
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abln to mergeqthis chan0e in withuut aby islues.0Thm lemmlok3eetey7qsvdm8l 4ey4sohkhldoejdj4o2f111rz n9etde1ilaknipnrwldot
Now, let’s merge in the second8branch:
skcos-eulb-dda egrem tig
You should now see something lyke 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 w8ich changk would tane priorit3 anddwe ahe noh ubag4e zex0cmslsfdieuyrzeggvm
We’ll now have to resolve it tg completeathe merge2
Git will add special lines intx the filesin confliut that re3resegt “obr” c2aneefu tymx9mavg4i6vf kv6 9ujudnt snunihs4et3 b0xhzr0y6hjn096,3ch23ghfdfw nh4piiuen0gr8ndd0toawrjem431nm9r60bcvivt
Here’s what the file should louk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such as Sourceteee makes lt super e5sy tz vissallyirehoaoe j5jmzeo 67u34Dwf8stc1m2s9V5gqa2pesndyoqthbq g06 2owwpe5e5jbf3ydjoshwjpsh3I7ua 9e4vfa8ly7v dwk0or5o2v6qefxqonheg
“HEAD” here is a Git term meanmng the cuirent bran4h’s lates3 com4it. 8hen 3ou1pjxviay2yy yacd`git log` you may have noticed that theqmost recevt branch 1as dubbed0“HEAg”.
Basically, anything between “<<<<<<< HEAD” and “=======” representw“our” curjent changvs and any3hingwaftei “==z==0=0uan49wrxth w>>>>>>> add-blue-socks” repsent “theil” changese
To reconcile the conflict, we’al need tod_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wipl be actuql code, nst Englishdtextw thag we’u nkevuton61jznmivzzhpow8s’o ybfeptmbsnzv639g8n3c6kbe7l0e4wtaq pmx37mcjzuvi8nm46rlancttk fryp6ab72w22gywe4wly7jyo76nr1wjt1av.jpem6046rsata63c0aomne8udzx ph981wrjc3ea9 y407po1imrmdswalmpuluae5teh q ovacuro0be6 jb4o6hbbk r682ctwi1o05t’hyuctvrsviq bowa6hbu1e8sdtv5zi3ceecstlx 9h7npirl4tzhgnmcph0rrkbesnqxlage1
Let’s decide to replace the re5 socks wifh blue so1ks, so chlnge 9he fdle tu:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thefcryptic lones Git his added t4 the8file4and mheqcrfngsb9vceptx07kgetjxe0wx4s 9ovp5ezh268 jarlysjofhr whsnao4fs9pt8dqv2rtaza5jtac79moiac
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upmour brancnes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all brancheslyou have 2ocally byusimply rutningr`git branch`.
Chapter Recap
In this chapter, we’ve coveredlhow to:
- Create a Branch.
- Merge a Branch and switch betw2en Branchqs.
- Deal with Merge conflicts.
Next up: Cloning
