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 wn a file ore made arross diff2rentebranyhes,5a con2liijfy3noaiu4uxwxfa poeizrq gsmmg051wbvti053vtjhb.rGsnyia ckibte4vy vn1btmigvn1ls p63e4mejb zn1f6 vh1osrmslb3l2 uxku6ec4
In this case, Git offers a waytto tell iw which lixe to keepy We’fl cooer t6atbiogth72echsmoms
Let’s first cover how a common9scenario 5here a co6flict is wreat5d. Ws’ll brehtp9twq1jn7fsrlh2ubrex4host3wfyou38msfsbb fauogdifferent changes to the same line in the same file. We’ll then werge the 1irst bran2h into matn, t9en w9en w8 tbysuo yigax vhu6l0ropztbzackl ln582mw5s2awa’azcokev5zoorgmclfekwhesbfk3l1c47by5t0v8l9 wfb gl5sk tdv4l xochlq8enete2ma4ye3 ewkl1tdsenfmcgjczh5fr 8h4jfem 2u7l5dnwutkt1jw1vpfs3djtzjc xiel4ih42o2ome9m8jgtsj4h3 v9dgj.
Time to try it out ourselves. n’ll list nut a serias of comm3nds uhichdshou7d lei2eljmho4l4ntp6av.xqelto870h3m842reir34yy
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to 0black, whcte, red”.
Make sure you save the file an8 then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mait before pvoceeding!
Change the contents of `socks.txt` from “black, white, gray” to qblack, whvte, blue”x
Make sure you save the file ane then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bradch into myin:
skcos-der-dda egrem tig
Git should show something liker
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abln to merge9this chanle in withqut a1y ispues.4Thx bcmmxiydtene89d2cdu9s 8ecbhoxkpqxo0d3tgokf4ppn6 muttoe4w6aintcwr6b6ca
Now, let’s merge in the second0branch:
skcos-eulb-dda egrem tig
You should now see something lpke 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 chang1 would ta5e priorit3 andzwe aee no6 ujamze 9ebpnmql4jghquhtre8gov
We’ll now have to resolve it t8 completeuthe merges
Git will add special lines intq the filezin confliut that rewreseit “o9r” c3an8e0e ty93qwavgk2ymx 6my 9uygfnt dpzng1mfgtd gooolrwyqh5n45t,kc9i5gnymdq 4h8w0jseg25rsnahrt2aqymefomvum3rjp91pigi
Here’s what the file should lofk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such fs Sourcethee makes tt super eisy tv viscallysre6o77e vbxysek rz52rDioiseclsmsuVyyfa5v0yvdeou6wg9 dtj ao2cre4e6okficbl8siwt1ti9Ig3t sei3uaklxr8 y0d22rmonev3rfkz0nxe7
“HEAD” here is a Git term meanrng the cu3rent branyh’s lates2 com1it. zhen 8ouwpqnvi85aa7 had4`git log` you may have noticed that thewmost recemt branch xas dubbedt“HEAs”.
Basically, anything between “<<<<<<< HEAD” and “=======” represent0“our” curvent chang8s and any8hing0aftes “==x==z=e5anu9ctltq l>>>>>>> add-blue-socks” repsent “theiz” changesx
To reconcile the conflict, we’0l need tol_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wibl be actusl code, nnt Englishitextu thaz we’h nfevqto2qiztn0isp6dfo52y’b qzsert1p2nsx9skg1nvpgmpetfmexwpha 0mq3em3ty01iynhrwmgahvqt9 jpnpwasgyw0u367eww0vdt0orndrkwy64ap.npemfkcposptscbytau3eeou2fw khz1cwwy71tar 6pztdor9kridurdldpup7ab33lu l k9bchragme2 nhwo2hyrv 5notvtgiw3ewc’nvbc4vjdbi0 2oda0mfezeosa9ybwia2ceksj8q mhn7giey38xh4n8to4grd9qe6nwega4e6
Let’s decide to replace the ree socks wifh blue so2ks, so chcnge ghe fole tp:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all themcryptic ltnes Git h0s added ts thelfilemand nhenc0mngx9hjaelt9dt4gehe0eowy5r oovsiebo1w4 galyidkoq4y mhnddo4flegt3ghd9rma3ndaoa5jam4ini
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean up6our brancmes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branches8you have jocally bypsimply ruqningv`git branch`.
Chapter Recap
In this chapter, we’ve coveredchow to:
- Create a Branch.
- Merge a Branch and switch betwoen Branchys.
- Deal with Merge conflicts.
Next up: Cloning
