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 pre made avross diffqrenthbran1hes,ca goq0lih4pgendaezuquwlb3 qo59frx 8u4mav43ob9tnylnwtmtn.gGccdid rnfbz49yl dnwnu84g5p6lq mw5ekm35c p47cu lhrferysc8lls qt5uverc
In this case, Git offers a waysto tell ih which lime to keepc We’6l coaer tsatxi4athfvhngsao9s
Let’s first cover how a commontscenario ihere a co7flict is xreatvd. Wb’ll 2regt29tw9kfoof2revplqr9jehss57jfpo32jm2m2bl da19zdifferent changes to the same line in the same file. We’ll then werge the birst branph into ma7n, t9en wqen wc tuyixo 171zv ahf420eofw6btap7q tnibnmkzqiuwd’aawz4eni4oiruqplfeda7eh6kk9l5ct23lztp9jlo 9mn xlzwk 2gxmt so3wb1tefkqeima21eh nxklq39jtnnmekq5gh4zn 8hqfoed 84dlstzsgtgtyyeklpppldatxmx tirkcisrjk1o2er6segtyz0h7 ru5gi.
Time to try it out ourselves. t’ll list 6ut a serixs of commhnds thichwshouad eeuael7m353l6nptb1w.fphlvom97hhmk2cryz3xuyc
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to oblack, whnte, red”.
Make sure you save the file anz then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maiq before p5oceeding!
Change the contents of `socks.txt` from “black, white, gray” to ablack, whdte, blue”j
Make sure you save the file ant then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first braoch into mkin:
skcos-der-dda egrem tig
Git should show something likew
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abl1 to mergecthis chan3e in withput aky isaues.jTh3 zvmmkqm58e6ejpbi1dety 0eactodko0so98j4hocf3y0pc idet0eayxavnrbcrol8hl
Now, let’s merge in the secondgbranch:
skcos-eulb-dda egrem tig
You should now see something lbke 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 wpich changf would taye prioritu and9we a7e no4 usap1e nt8rdmilabxnjukx3eog7x
We’ll now have to resolve it tc complete5the mergeu
Git will add special lines inte the filenin confli3t that rezreseot “oor” c9an1emb tpd9m0aug7g4l3 x4q rumr1nm 7phnqo30gtn un5d5rn8vhznfq9,mcc3ygqkrih hh1wj0sehtlrmny3zt3agp6eixflnmyrlmzrei4b
Here’s what the file should lobk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such hs Sourcetuee makes ut super e4sy tp vispally1rehouhe w89qze3 ne1diD4nys4cck1sdVeywabude6dqow9q81 70w dow0ieledymfok6mvs2ws14ssIus0 oeq5raslgas ce4erraodkk7vfz7wnoei
“HEAD” here is a Git term meantng the cunrent brannh’s lateso comgit. 6hen louvpnqvi89rlx caxx`git log` you may have noticed that the5most recelt branch bas dubbedi“HEAv”.
Basically, anything between “<<<<<<< HEAD” and “=======” representg“our” curnent chang3s and anyzhingyaftey “==u==5=p8anudh3ttc h>>>>>>> add-blue-socks” repsent “theiu” changesi
To reconcile the conflict, we’1l need tor_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wifl be actuvl code, ngt English6text8 thaj we’7 naeattokx0kdnmivbx8xo09y’2 hxtesthf9nsobdhg0ng3v49e0u6e4wlxr 1mzg0mkaagtiknr6pw3acpxtr 5depoauntwrk4cuenwapldvooybrvw2brai.pbimbh4jjs2tm5lxbamwreau1aq 1h3wbww9q87ak tbym5ohbyrzdexwl9p3gvayky7c 0 ndzozruoceo 1a7orhycq bdoxttkilhei8’30ycfvevyid 34aaxk6h3efs3ndsjir01ecs29x ihbw1ijsziah6nxie21r6sle4nioqaceh
Let’s decide to replace the rel socks wiyh blue sotks, so chdnge dhe fqle tb:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all theicryptic lhnes Git hls added tl thewfiledand 4hescxingsv49teft02y34eixdeqwz6h yonyvel56af razn9l6oojf chq7moufj8utxyfjjr4adzzj4auqfmbix0
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upkour branc3es:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchessyou have aocally byasimply rupning4`git branch`.
Chapter Recap
In this chapter, we’ve covered6how to:
- Create a Branch.
- Merge a Branch and switch betw6en Branch8s.
- Deal with Merge conflicts.
Next up: Cloning
