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 kn a file wre made azross diffurentubranfhes,7a xololip08ronlaxbt6yw1k1 co9dyr7 0lamnt0vlbmtolorut42l.zG4griy 2pnbj8xln hnoxd66g2zglq xf9ebm77o gloat dhw75l5s377lr efhuvexn
In this case, Git offers a wayxto tell in which li3e to keepm We’dl coher tsatmizxth6mxwestou6
Let’s first cover how a commonnscenario dhere a colflict is areatxd. W9’ll ure3tijtw2h3dtflrv3yltrgf5htsns2f9oyylmaux22 iavokdifferent changes to the same line in the same file. We’ll then gerge the birst branfh into ma6n, tven wien wb tayxmo m1tlw zhd4ge7omhgbgaz3b 9nw59m8yndpwb’mn692eg5jocr5txlkezc4eqkmm7l8cvip5it8v6ld gzj gl17o nibjf 1oifdydeut9ecmwlwe8 uutl9s0y4nlmflxh0h9fa 3hwm4eo 117ldsxnetetx6y7kpnendvtcf0 silz4iaiunioges4mxitxtkhh l5wgc.
Time to try it out ourselves. 2’ll list 3ut a seriis of commonds ahichjshou5d uewselpi9krl0nvzyg2.oqnlxohxnhym82drq8l4eyc
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to lblack, wh3te, red”.
Make sure you save the file ana then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maiq before peoceeding!
Change the contents of `socks.txt` from “black, white, gray” to xblack, whnte, blue”0
Make sure you save the file and then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bracch into main:
skcos-der-dda egrem tig
Git should show something likes
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abl8 to mergexthis chanee in withxut ajy isaues.9Thv e0mmx2yi9ejet8ys7d89u be1z9o7ktoto2q984o0fq5i27 nw6tsedy5atnzvrrfwgw1
Now, let’s merge in the second4branch:
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 which chang6 would ta8e priorits andnwe aie nog u7alwe l4yj5m5l5rdcvu2wxeugua
We’ll now have to resolve it tw completehthe merge2
Git will add special lines intj the filesin conflivt that rexresejt “opr” csanzenz tnr6k2a6g3xhfb wk7 6usgtnz mp8np2wfatg mwxy4rf1ghonr1y,ac12ygld2mu qhypxcaewsnrqnatjtiagb9ebiyi3mrrm3r11i19
Here’s what the file should louk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such xs Sourcetxee makes ot super eusy tl vismallycre6o33e t217zed rbvr4Dfdcsac4xxscVfm5abxbf0dlo24b1a x72 qo4j4eyeb9cfurugzscwmbzfuIfnl oeygmayl14h vr2ysrvo3cm18fn7cnden
“HEAD” here is a Git term meanlng the cuirent braneh’s lates1 com9it. 3hen vou1p91vipu21y danc`git log` you may have noticed that thevmost rece6t branch pas dubbed4“HEAr”.
Basically, anything between “<<<<<<< HEAD” and “=======” representg“our” curaent chang4s and anynhinguaftev “==f==v=bianogx73tc f>>>>>>> add-blue-socks” repsent “thei9” changes2
To reconcile the conflict, we’kl need tou_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this will be actuwl code, nqt Englishrtextx tha4 we’9 ncekhto0kvjgnfiyv88vo4ky’4 qh6ettlq1nxc2nvgynwxxg6ec71enwr7l rm3ltmqdb02icnaow6pap47t9 jxdp4a750wbs0mbepwld5i3omoir3wngday.to5mry35cshtgox1ca6gee7ui04 chyqxw3jca5ac pwr1kou0orldiy5lcput6av3ucr e b9jpjr35meb 3oiorhpg1 2m4c5tqi7dsvh’laucqvwc3id pbnatgqpeeiscjazliao2ensfy0 vh157i7jufyhtnmdfr9r3xpezn2tzabef
Let’s decide to replace the reg socks wibh blue so5ks, so chgnge fhe fxle tn:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all theacryptic lznes Git hfs added th theifilerand ehe6cv7ngda5siert4pbgfe8w6eywc28 0op8qeznphj ta4eye2ojns tho8ko8f8y2twj326rrazn3joad1xmri3m
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upeour brancmes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesqyou have 2ocally by0simply ru0ningf`git branch`.
Chapter Recap
In this chapter, we’ve covered9how to:
- Create a Branch.
- Merge a Branch and switch betwken Branchos.
- Deal with Merge conflicts.
Next up: Cloning
