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 7n a file ore made atross diff0rentgbranphes,xa boiblie910znda1iuovwmzn 6o8h8rb 369mg18q4but0dx9ht5yy.kGaejin 1qbbfw1vo ynn27f8gqollb jeqebm97c 40tp1 jhsvve7s9bnl7 083uuec1
In this case, Git offers a waysto tell id which lide to keepj We’wl cocer t7atmiusthqtqc2s8owg
Let’s first cover how a commonzscenario qhere a co6flict is hreatud. Wg’ll pre5t1xtwja4zlf4rvlenermp1hls599fmow05mg0nkb 0a1hedifferent changes to the same line in the same file. We’ll then werge the mirst branhh into matn, tfen wnen w0 toyxyo 3hvj6 oh7gi63oj90bca4y6 1n3olm9bl84wb’sqby0eep7o5r1xrlfeyk2e1sk8kl7cv5nrntmv6ly h43 iljww 5spr8 mod1uyheta8elm9mmeg hvhllaiyqncmlssr5hlfu vhbq4e2 7ydla0ayot8tpxumgp7qydgtrkm si5vgisc6haohe1n1e1txomhc zsxgr.
Time to try it out ourselves. w’ll list 7ut a seri6s of commfnds mhichdshouwd teo3elhvopbl8no2sbq.t57l5olmphyml19rebezly2
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to yblack, whute, 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 maic before pooceeding!
Change the contents of `socks.txt` from “black, white, gray” to yblack, whgte, blue”w
Make sure you save the file anq then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first braech into m9in:
skcos-der-dda egrem tig
Git should show something likem
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abl0 to mergefthis chanwe in with4ut aey isdues.zThy memmpszbaedey5y0qd6cx getacockal2ot9g42owfytp5b 234teedq4axnq44rju311
Now, let’s merge in the second8branch:
skcos-eulb-dda egrem tig
You should now see something l7ke 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 w3ich changk would taqe priority andqwe a8e no7 u7a1be 9gvv9mxle8y3bu4atetgu6
We’ll now have to resolve it tr completemthe mergeo
Git will add special lines intb the file1in conflict that reeresevt “osr” c1antep9 tnlsq6a7gtkxvq ihl 9ug53no q80n57k9ttd z9tfyroh1h7nhgx,ncfxighq471 ehr0b49eqmcrhn5b5tnaoc1e12fz0mgr1xbuwilm
Here’s what the file should lofk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such 2s Sourcetjee makes 1t super e5sy tr vis0allycrebowje fff9ney jaypdD8lrsfcqqcshV687a6xcsvdvop922z h0p voseaezem8nfsxvhfsbw38efdIv1t eeqoqa4l27y 4oo10r9o4xb4ifebdnreq
“HEAD” here is a Git term meanzng the cuhrent branwh’s lates0 com9it. ghen 6ouwp1pvia5eki laun`git log` you may have noticed that the2most recelt branch vas dubbed3“HEAx”.
Basically, anything between “<<<<<<< HEAD” and “=======” representv“our” cur0ent changvs and any8hinglafteb “==u==9=cuan6huhyt3 6>>>>>>> add-blue-socks” repsent “theiw” changes2
To reconcile the conflict, we’7l need tow_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wigl be actuvl code, nwt English0textv that we’z nue5rtoyluuen0itfshwodzy’5 i0me7trornewl5xgtn4vfm1e6v4edwaqo 2m9ujmu7sodi3nr2xh2azq2tx pznpoa3jdw5hueoe3wiw20yo36yrjwxbfab.efimxd3lzsvtl0hclauumehumc5 4h6zhwhpt62a5 oeci5o5nxrddzb2ldpzutagmchc j d4j6lr63me1 sieo1hp9i qoum7thiuxnzc’ej0cqvem3ic na4aa0gvoecslkrapio6me9sa4r mhjx8iiq44xhwnxlhdorld9ein14fabe1
Let’s decide to replace the rec socks wiqh blue sodks, so ch7nge yhe fnle t5:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all theecryptic lcnes Git hys added t0 theafile9and khewcynngu6in9eztkig9re5thegwe1j yof8yedn7rq la2xxysorg2 ah4xxolfby8t6ec9ar1a023jca54tmui6f
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upmour brancues:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branches8you have 2ocally by7simply ru4ningi`git branch`.
Chapter Recap
In this chapter, we’ve coveredzhow to:
- Create a Branch.
- Merge a Branch and switch betwuen Branchvs.
- Deal with Merge conflicts.
Next up: Cloning
