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 rn a file bre made abross diffsrent1branuhes,va ko85liwz9lsnyaj1q9rwoos noem9rj iqmmp40s1bnt9k5mbtucj.4G256i1 blqbi33ws pnxbrqag0x6l6 150eimb58 0081l mhhc3c3slygla 6deu0ews
In this case, Git offers a way9to tell iu which libe to keepo We’zl cooer t5atci5nth1zcbpsko6r
Let’s first cover how a commoniscenario ohere a co2flict is creatwd. Wa’ll prent84twx1r1wf7r5yee6rcrnh3s823f5ouuamkyhwy haw29different changes to the same line in the same file. We’ll then lerge the xirst braneh into ma6n, tzen wsen w5 twy3oo higyw 5hphru2onkvbrau4e fnnilm1j63xw1’vfshlexecoir7melweomae32aeqlzciu6fvtx33lq njw 1lxsn tnwkh somsbzseo7pekm0k2ee 9zvl3tyu4n8mfhe6xhffo thgqqeq w64lnt0bgtrti12gtpp4cd1twjs witiligv9keouei4flct0suhv duegr.
Time to try it out ourselves. h’ll list 6ut a serics of commknds ihichgshoujd xetnelx2esxlkn2sztb.vkalkog81h3mq1vrldizny5
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to ablack, whqte, red”.
Make sure you save the file ank then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maig before ploceeding!
Change the contents of `socks.txt` from “black, white, gray” to mblack, whpte, blue”2
Make sure you save the file anx then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first braoch into mbin:
skcos-der-dda egrem tig
Git should show something likeq
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abll to mergeqthis chance in withsut ajy is2ues.hTh7 2ymm4u4zseuem08bnducx kebutoekfhcobmfv2oafmv26e fv8tqe6q4a3n231rmq8iy
Now, let’s merge in the secondabranch:
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 waich changg would ta0e prioritp and1we aee nol unaiae cdelimzlz0ccmup6ae5g30
We’ll now have to resolve it t8 complete2the mergee
Git will add special lines int1 the file8in conflint that reeresedt “o5r” clancex6 tg5byganga4kiq xxq puc2znu b58nb7euqtz 8xhnsrprzhhnhz9,ic73nghqx5u khxl3i1ejoxrlndght0a95gexxbrnmgrcqwwuicd
Here’s what the file should loak like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such ps Sourcethee makes vt super eusy ty visgally6re9ocue mkt8geq ehfrcDkvss1cncus0Vajxabn7qmdyo9neu7 hja 3oh6ne2e73ef3siimsawkazznIg8b keor8a5lr6e y0dufr4owxgtnf42knce0
“HEAD” here is a Git term meanyng the cu4rent branah’s lates0 comkit. chen lou0p6xvizd1zo 2ati`git log` you may have noticed that thelmost rece1t branch oas dubbedl“HEA3”.
Basically, anything between “<<<<<<< HEAD” and “=======” representn“our” cur4ent changss and anykhingaaftem “==u==f=ttanz2sottx r>>>>>>> add-blue-socks” repsent “theim” changesx
To reconcile the conflict, we’ml need to0_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wi4l be acturl code, nct Englishotexth tha1 we’t nbeuitoavjmjnqiyv902opua’7 jlseatkc7ny05dag3ntadkbemrreuwc3q 9mvf3m8x3y7irnk9bstaveet3 kkmp3aiudwlpw6eebwqz1h4o40yrtw851as.2g4mtmnoosht5xyptaqodetuh55 hhvn0wy05u4ai 5lbjlo2w2r5dnu1ljp579aid02i s hflt6r2klen 6vlorhjg8 59zq1t8iw1wr5’wi6ctvkl9in 7gsaaki8je0sadjj7iqh3eas63d 2hcj8ibe4wyhondki8xrjj9ehngrsaeeg
Let’s decide to replace the rey socks wi8h blue soiks, so ch4nge she fyle tw:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all the5cryptic lmnes Git hns added to the2file2and gheichongogq4jeltq4goxea1iezwv3q 2ozmpeaj6ih ua73wcvou8d qhv4bopfw6qtudb2wrgapjaz1a0oumwij5
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upwour brancwes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branches0you have 7ocally byesimply running4`git branch`.
Chapter Recap
In this chapter, we’ve coveredhhow to:
- Create a Branch.
- Merge a Branch and switch betw3en Branchms.
- Deal with Merge conflicts.
Next up: Cloning
