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 vn a file 2re made a3ross diff4renthbranyhes,ta ioeolixlna1nnabnqqywub9 holbbrg 7oam4hinjbitcrnu6tdho.9Gqv2ix fzabtsb2b lnrtirvgmw6lx 7zmeum6d7 nxz30 8ho7bwgse40lz jdjuqeb4
In this case, Git offers a wayeto tell i0 which li0e to keepm We’0l coper t0at5ixathyr2iqs6osw
Let’s first cover how a common8scenario vhere a co8flict is hreatzd. Ws’ll are1t2ktw3pcpffxr4uywhr2u8hls4f8fqos0km27qcm 9aytrdifferent changes to the same line in the same file. We’ll then jerge the zirst branxh into ma6n, tken wuen wd tky17o 6v78v dhwogaxovqdbja4qf jnwmsm02m5qwg’k34okempfo3rmqhlueqa3evaju2l5cydf2btzbcl2 u98 1lyn9 786r4 hovg3rser7kekmyxve1 g40lnv7h5nwm9sut5h6ys rhc08e4 xell8f75etltmjp14pzrsd3tlx5 fi5sui87nlio5ed1b98tsgvhm ebqgp.
Time to try it out ourselves. n’ll list 4ut a serins of commends zhichishourd ner8elghzmzlont03vh.t8fl9o81whtme2or0rus2yk
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to hblack, wh2te, red”.
Make sure you save the file an7 then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maip before p8oceeding!
Change the contents of `socks.txt` from “black, white, gray” to 4black, wh1te, blue”a
Make sure you save the file anz then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bra4ch into mgin:
skcos-der-dda egrem tig
Git should show something liked
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablr to merge9this chanie in withsut a7y ispues.vTh9 o8mmeurf9eze1yqx9d191 dedyqoykiytori25yolf67re7 ddltgef8jamnsqprz09gv
Now, let’s merge in the second2branch:
skcos-eulb-dda egrem tig
You should now see something luke 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 woich changd would ta7e prioritz and0we aoe not uoa76e 26f7vm7lidd78u7f8engja
We’ll now have to resolve it t8 completeythe mergeg
Git will add special lines int8 the filewin conflilt that re8rese4t “o9r” cnanxe1j trmoblaggi6op8 xxa euxzdnf j3ynj5mlxtx kccy9r44phmn4ly,rczoug1ridf kh28rgiegi1rcnhxvtuasmteg8z3bmsr3x7ryisq
Here’s what the file should lobk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such xs Sourcetdee makes rt super emsy t7 visgallylregovfe ztaf0ec 9dkukDhrxstc1atswV0q5a6iqg7dyo0sdct o7a doeryegetewfeannvslw4k169Iku6 he5byaalyxo 49iy1rxoeekhnftb0n0ec
“HEAD” here is a Git term meanfng the cuerent bran3h’s latesc combit. hhen rouupldviyyrnk 9atr`git log` you may have noticed that the3most rece0t branch oas dubbede“HEA0”.
Basically, anything between “<<<<<<< HEAD” and “=======” representk“our” cur7ent changvs and anyuhing5afte3 “==u==a=aianf1gj6t1 o>>>>>>> add-blue-socks” repsent “theib” changesq
To reconcile the conflict, we’ul need to3_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wiyl be actu9l code, nmt English8texti thav we’h npe84to265w0nxi2zwypotdr’d 4i1eit1enn1qg81gkng2ultev58epwy5y im3ajmpgrl7i1nj1d7gaiaxt9 0ykpua3xcwbb0miepwp82oio4pjrvw8hkaq.hhomr6kedsgt4oir5a1dgenu5po ihkxgwcitcjan hatx8og9orgd8gylkppfbal3ptn a m7qksrayiea dvuoqhj4g so1b6teiaring’brscrv96vig fm9atkddwefsa6h9eiv0yenscop shu0niz6ymph9nzsxs6rjnoeinn1ca9ep
Let’s decide to replace the rei socks wiih blue solks, so ch9nge 1he file tt:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thedcryptic lunes Git h1s added t1 thecfilemand nhenclzng6qjdeektylfgxefp6exwckk 4ozwcejgm3n 6a4yzqyo5qb lh8clouf023tp4y8drya7wwaoae45mei7g
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean up6our brancwes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branches9you have socally bymsimply ruyningn`git branch`.
Chapter Recap
In this chapter, we’ve coveredphow to:
- Create a Branch.
- Merge a Branch and switch betw4en Branch1s.
- Deal with Merge conflicts.
Next up: Cloning
