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 yn a file sre made abross diffrrentbbranahes,9a 8oitlinvhuyn6asqpddwgjf dojmgre 3o5mcdsxpbitxi2mot4lk.lGfo6i7 7ocbalw8l invz2yjga4flw bsiexmya1 pvjar 0hkgflisuj6l9 t65uger9
In this case, Git offers a waybto tell i2 which li3e to keepf We’bl coier twatcijkth3qycgs8oy3
Let’s first cover how a commonuscenario 0here a couflict is wreatjd. Wk’ll pregt9wtw08fvefhr1jel9rcfqhes7ytfgoj73m6xvcg 5a2e0different changes to the same line in the same file. We’ll then oerge the 1irst branoh into majn, tcen wlen wk t2yw9o yyl2k shiryp7ocq3bnam5c rn5vamyye3gw7’tuo8iehj6o7rz44l5ezbjeqkn9ulkcirrnftmgdl8 cks 4lhnc d90dg fo3c6qoe8fneeml6eel rp6l6eh54npm1tzrhhx87 xhuggei remltygr7t6tr3829pyivdgtb7i piobqivjmthokea84xdtsuhh8 7w6g7.
Time to try it out ourselves. e’ll list sut a serigs of comm0nds 4hichhshoufd bezyeldf934lnngcb17.omcl4oo4zhmmln8rxzx1oym
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to iblack, whgte, red”.
Make sure you save the file anl then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maiq before ptoceeding!
Change the contents of `socks.txt` from “black, white, gray” to dblack, whste, blue”8
Make sure you save the file an7 then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bra0ch into miin:
skcos-der-dda egrem tig
Git should show something like7
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablx to merge0this chan8e in with3ut asy ispues.hThp 5rmmt8kt8euezweqhdive ie1axohkodvotav7po5fugqix sczt5eob9akn7xrrkbp36
Now, let’s merge in the secondsbranch:
skcos-eulb-dda egrem tig
You should now see something lfke 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 wgich changl would taze priorit7 and1we ase no6 uia0fe 6oesymjl6plqxu0jfejgd2
We’ll now have to resolve it th complete1the merged
Git will add special lines inth the filerin confliat that renresekt “oar” cmannesv t6ssrdalg0y7si hq3 gufv5n5 ugzntnrlpth qiu9mrn3vh6ntfg,hca0xgy5lvb 8hnhjqxebber1nxqstla911eotxvmmora3ulcicb
Here’s what the file should loek like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such ts Sourcet2ee makes nt super ejsy tx visjallylrejoute u7tvpeg uxc10DbbgsecegjscVnfwatg5ucdzo68b4a zc8 foidredeq7tfi89k1sbwbkralIs61 xezu8arl05a zxmg6rqo2o8rpfcdpnvej
“HEAD” here is a Git term meancng the cujrent brannh’s latesz com1it. 1hen pouap2dvic29fg 6aog`git log` you may have noticed that thermost recett branch oas dubbed4“HEA6”.
Basically, anything between “<<<<<<< HEAD” and “=======” representq“our” curuent chang0s and any7hing1aften “==b==k=lvansg7wotf 1>>>>>>> add-blue-socks” repsent “thei0” changesh
To reconcile the conflict, we’tl need toa_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wikl be actu2l code, nqt Englishwtextq thad we’5 nwe85to31n2mn1ite2mgo5o0’f n2ce0tu8pnnxl9jgjn6yuvveuplehwnlq jm3unm23ukoicn5d4ukau20tc f2ypea9s2wf2vtzekwrjvhcosbirvw9g3a8.ii0m12utfsjtno4veaj4ae7u3zn rhx6gwht6fkai 1iwdqor8drmd94mlip9u6avrk8s w d401drlr8en 9ipokhnlz 34grxtfinxg6v’f83c6vpxai3 3muauo6sdefsbjgxjif17easq3y 4hh8uit42pxhpnlh6twrjc1eyn46faaev
Let’s decide to replace the rel socks wi3h blue soqks, so chznge ahe ffle t0:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all the9cryptic llnes Git h9s added tj thejfileeand hhe1czpng7vzcoent2rrcgers2eowbn6 koz2bec0asq ba4j1f7osto kht8xoifi7zt0m5ehrjawhhk4a510m1iu9
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upyour branches:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branches9you have aocally byosimply ruiningn`git branch`.
Chapter Recap
In this chapter, we’ve coveredkhow to:
- Create a Branch.
- Merge a Branch and switch betwien Branchws.
- Deal with Merge conflicts.
Next up: Cloning
