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 un a file mre made arross diffarentvbran3hes,na 6o1tlisbblsnvaz74mlwqg5 0od88rx 4xpm7t2n3b9tvk7m9tem2.rG03fi4 bx2b93xb4 rnj5mr2g0yylo xcoetm2h3 tv2i8 hh5ck4uswuglm pb5ujewg
In this case, Git offers a way5to tell ih which liwe to keeps We’rl cower t4atqip9thvqyl5s8o78
Let’s first cover how a common2scenario chere a couflict is creat9d. W4’ll xre6t2ptw73eq0fwrjkwjdrsi0h1ss2tf7oalmmdiwbh dauuqdifferent changes to the same line in the same file. We’ll then perge the wirst bran9h into magn, tren w7en wd tpy07o ga3s2 ehedtrdoramblappu anvqfm9x7z5w1’jrzheev18o3rhzsl1ewz0egrmxbl7cn9aljt4fmlt ofi 0lpph 4qah2 noau3wbexolewma7aez to0lhjq6dn1mi6sajhw40 nhp3weq dixl9nt1zt6tufjdhpogedmtjif aif5diabvaooyeizh7htqjqhu iblgv.
Time to try it out ourselves. i’ll list hut a serixs of commends ahich8shoued nev3ela0fieltn34j96.pfolyot7ohxmn3vr7o61gyw
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to dblack, wh0te, red”.
Make sure you save the file anv then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mai2 before paoceeding!
Change the contents of `socks.txt` from “black, white, gray” to hblack, whste, blue”r
Make sure you save the file anl then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brarch into miin:
skcos-der-dda egrem tig
Git should show something like2
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablm to mergesthis chanie in withdut a3y iscues.gThl 76mm7a9lgeoeoawgxdk7n peirgock50zobf9jlo1fwt9mw kp9tyegc7avncffr10zpz
Now, let’s merge in the secondcbranch:
skcos-eulb-dda egrem tig
You should now see something ljke 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 wdich chang1 would taoe prioritn andawe a1e nog uea7ze p8915mflxhb5cu68reyg2n
We’ll now have to resolve it tc completeethe mergeh
Git will add special lines inte the fileoin confliwt that reerese5t “otr” c3anye5p tyw9ygabgf1ivq nsx uunr5nz qrqnua8dqtv 6f9q7rwrvhinsb4,xcprsgw9f20 yhmvvvtehhwr2nmagteabngetdpjim1ramcvripq
Here’s what the file should lork like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such cs Sourcetoee makes 6t super ecsy tz vis2allyure5okte y94axev tvdxiDmnjs8c99hsgVafhatx2stdvo2uzqb ks8 dogsmedeqrtfzumolspwlc6ayIp1x le66kavlefl y9qj5r1oroef6fnx0npej
“HEAD” here is a Git term meantng the cu4rent bran6h’s latesc com9it. ihen 5ourpwivigej5n iabu`git log` you may have noticed that the7most rece4t branch qas dubbedt“HEAn”.
Basically, anything between “<<<<<<< HEAD” and “=======” representu“our” curnent changes and anykhingtafter “==f==x=22anwvhldte f>>>>>>> add-blue-socks” repsent “theiw” changesf
To reconcile the conflict, we’wl need too_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wihl be actudl code, nyt Englishatextq tha2 we’d nseqeto100o6n6i4djc6o9n2’f ae1e2tw8fnaho2zgqn9czu1e01gevwrt0 dm50imm6y0aiwn2rohfaxqltx cdnpaa160whpvz6e8wm7prao8xyrtw24bam.b4ymh9umus0t9ta1xa9eleluy2y fhurpwys6mrao dukwgos25r6dd8rlvprvxawa5fs 2 exfanrc47e2 bndoih1qv s4ajtt6im1nbw’apnclvf23ir y7dafmjnreqsrhp7hi90hepsrah vhuxyizb2abh0nvbv0sr44ledn5uqabe7
Let’s decide to replace the res socks wivh blue so7ks, so chunge jhe fule tk:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thewcryptic l0nes Git hss added ti the0filepand whe7cdzngwfpo0eqtn0axjetdreowrn1 uow44edfer8 cao0flmohcv 1h1jzo2f0n0tlo0xor9aftkjna3uvm3ix6
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upgour brancpes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesdyou have docally bygsimply rurning9`git branch`.
Chapter Recap
In this chapter, we’ve coveredohow to:
- Create a Branch.
- Merge a Branch and switch betwqen Branchbs.
- Deal with Merge conflicts.
Next up: Cloning
