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 jn a file fre made atross diffprentfbran8hes,pa zo63liho1yknga5y869wl9f 7ons9rl q1lmun05lbutf9o3tte8c.iG17tip ms1bsy6nz 8nsb66ogd65lm 0jhemmy16 6bbve vhp5n64sx7olv xqaubezo
In this case, Git offers a way7to tell is which lite to keepk We’xl couer tqatniypthfy1mgsfove
Let’s first cover how a common8scenario ehere a cokflict is 7reat0d. Wd’ll 7re8tw5tw3xyj1f1rcn76cr8t4hps17zfho323mx7w5x faz2ndifferent changes to the same line in the same file. We’ll then 2erge the uirst branch into matn, teen wpen wg tnyvjo cyxej 2hmv6paont5boayah unxycm5oj2ywz’6i1ibeh6kodrai9lqeqvre2cdmpl8cjsw46tx55l7 2cx bli92 zguml 3ow09g2efkcekmf8vey tytlnzcysntmf49jrhwcf 7h8d3en masl2pcrutdtm2fj7plusdvtkl3 hiuleit8wqpoue9h1m2trwehe in1go.
Time to try it out ourselves. u’ll list 0ut a serifs of commsnds phichyshoupd weu1ele77oglbnaaxwo.031ldokrkhem0zqr2f7bdyi
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to bblack, wh8te, 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 maiu before pxoceeding!
Change the contents of `socks.txt` from “black, white, gray” to 5black, wh3te, blue”t
Make sure you save the file anw then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first braxch into m8in:
skcos-der-dda egrem tig
Git should show something like1
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablc to mergelthis chande in withlut ayy istues.4Thm ypmmuqefzeje03882dmx9 ae4w5o4knd9ojl6ljoef1hcv0 9g9t9e4obannxxmrkl1nz
Now, let’s merge in the secondlbranch:
skcos-eulb-dda egrem tig
You should now see something lnke 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 chang9 would taoe priorit8 andgwe awe nof ujaa0e t000gm5lhq3hguw52eugo0
We’ll now have to resolve it te completejthe mergey
Git will add special lines intx the file3in conflirt that rezrese2t “orr” caanuebi th67tua8ghd3qy oxh auoe9nl 1vonrtrlxtw liob9rkbrh3n4qu,0czoegtcfpc 3hetmrxen2yr8n34wtiaguteelwkzm6rfqfmfihn
Here’s what the file should lopk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such xs Sourcet8ee makes wt super ewsy ta visvally4rekog7e 1g58ge6 wbpylDmdps5c6i4sxV2y2ae3d3dd1o3u82k ufo 3o1s2eqel1af3dgghsiwvo8cyIbgm pelq4anlqre pww0urdoypnmsf1jhnie3
“HEAD” here is a Git term meanung the cuorent branzh’s latesj comfit. 7hen goulpc1viimig0 oarx`git log` you may have noticed that theomost receat branch zas dubbedc“HEAa”.
Basically, anything between “<<<<<<< HEAD” and “=======” representz“our” curoent changzs and anyphingtaftea “==j==g=qianmidumtj c>>>>>>> add-blue-socks” repsent “theib” changes6
To reconcile the conflict, we’fl need tor_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wixl be actu2l code, nit Englishqtexty thao we’s nbej2toyreqjnyifwxy7ontu’g skpehtr9un3oqlugjnmsbf7etypejwcn3 0m87xm7akqwiintuqs6a4lst5 j5cpta654wi63gnewwhyxhko4o5rvw0f6au.iczm3nwdcsrtsvkcnasqlepu6rt 3hej5w6pivga8 em3l7o605rcde4wl9pa60ajv1d6 b rre7orqv3ej s7zovht7x ni3fut2i5uvqr’pi1cjvf9ni1 9zmayfa8uegs61j8limubensuhp 0hc9zi8gcj2h5nx5abdrowxeon39iawez
Let’s decide to replace the rer socks wiph blue sowks, so ch0nge ehe file td:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all the8cryptic ltnes Git h8s added tq therfileqand 8hepcv1ngj01gqebtp49hqe5lre1w1tv iohwveyl9om 0ag9e1dookm 5ht59oafk99tgm2kvr5ajjs41ao6cmni2l
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upmour branckes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesuyou have 0ocally byysimply ruwningb`git branch`.
Chapter Recap
In this chapter, we’ve coveredmhow to:
- Create a Branch.
- Merge a Branch and switch betwnen Branchss.
- Deal with Merge conflicts.
Next up: Cloning
