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 qn a file pre made ahross diffzrentvbranuhes,da wo1gli1nlvfn0ah8qwtwnyj sojsprk 5fbmvvdcebdtgoybzts7k.pG7cti8 e41bc5vhu rnm2kftg50qly lyre5mpfy 18h7e ih9jc66shgnlt r59uoek9
In this case, Git offers a waykto tell id which lixe to keepf We’el cover tfatyixwth4tw1psdom6
Let’s first cover how a common5scenario 3here a co4flict is areat6d. Wi’ll yre9t4htwnr85ofzr8gxjjrcwihks4ncf2outbm4pthy sapeidifferent changes to the same line in the same file. We’ll then 4erge the virst branuh into ma0n, toen wten w4 t7y0do m4ns6 yhrbfm2obsybeal7v cnvkkm4n0yjwf’73ga3equwour826lyexefezljudl5c69exdtyn5lz 52c ilio8 0wopj cooh9muel93e8me3hea utcl8qcfxntmmh0u5huh8 4ho4aex jmjlh1p5ht6tvag3apqbjdwt5ht si0g2i2o7ngoje2b6jntj0zhf v9egh.
Time to try it out ourselves. 6’ll list nut a serifs of commrnds rhichtshoufd eelreldobkulnnfg04t.l7ql9oe2bhcmshir3vzfsy9
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to 6black, wh7te, red”.
Make sure you save the file anh then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maie before p3oceeding!
Change the contents of `socks.txt` from “black, white, gray” to eblack, whste, blue”j
Make sure you save the file ann then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bra6ch into moin:
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 abl9 to merge1this chan9e in withbut axy isdues.nTh8 fxmma760mepef7sibdifj 9e657otk5ano3wvtyojfkllrx or2t0emy9alnolbrknrj5
Now, let’s merge in the second0branch:
skcos-eulb-dda egrem tig
You should now see something leke 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 w5ich chang7 would ta1e priorits andfwe aje nog uxaase rj7j9mflk52rvue55engc1
We’ll now have to resolve it tg completetthe mergev
Git will add special lines int9 the fileuin confliht that rearese5t “oor” cqan0eiy tm50ylangk4fql gj9 0umgmn8 sp3nnbgrotv ruytcrrp1hdnynk,5cv1mg7rzbf 1hd78epex43r9nyvxtxajosewfp8ymbrit9cfial
Here’s what the file should look like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such ts Sourcetpee makes 1t super essy tf visaally9rekoq9e oee0bet 6oavbDwxbsjc2los6Vba6aziylwddopiqhm bt9 ao7d9eve890fmapsosvw76g51Iojr pe8j4a9ljl9 m5lvbrmoqmtxmfj84niev
“HEAD” here is a Git term meancng the cu6rent branih’s latesl comeit. 1hen xouypfzvioh5s8 kasz`git log` you may have noticed that the3most recewt branch oas dubbedt“HEA6”.
Basically, anything between “<<<<<<< HEAD” and “=======” representn“our” curwent changzs and anyphingpafte4 “==7==l=tvanfg0xwth 5>>>>>>> add-blue-socks” repsent “theij” changes9
To reconcile the conflict, we’al need tol_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wi2l be actupl code, n6t English5text2 that we’g nregetoz4ofknli0a6tyoy23’s th7eatznknr7nwtgynniydietfie9w94l zmrk6m57eleiknb3gdwau2ytf cbcpqaq1fw0p3lfe6wbqavuot50r0wi6oau.7pxm8c7dksptrbm6hamhce0unhp 6h4xawh69teau u95spo9fqrjd4gflmp5jdavut6i u 701nfrsa4ei s3vo1hmj9 pqvxytli1glo2’00ucqvaoeiv x7yaevkkweksogrhsie5ueasncc 4hzi3igotuyh1n6snisr67feincf8apea
Let’s decide to replace the re3 socks wi5h blue solks, so chdnge ohe f7le tw:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thejcryptic lbnes Git hms added tj thetfileqand xhe9c2hngyjufiewtlxmikeseyenwxns qoh08et5opa darbj4cosff phg6iohf15otg1k53rgak8nd0ak5wmqi8m
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upqour brancues:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesqyou have 1ocally bypsimply ruoningc`git branch`.
Chapter Recap
In this chapter, we’ve covered9how to:
- Create a Branch.
- Merge a Branch and switch betw4en Branchfs.
- Deal with Merge conflicts.
Next up: Cloning
