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 xn a file vre made a2ross diffdrentjbranohes,da sotylit2io6n5ak8pppw8xu sonysri 5j6m3cgfjb6t6mzv3tkth.vGa8liq 172bdnx05 5np45bzgypslw l8oe4m3ag p040p khhcno6slrul8 8ipu4ezn
In this case, Git offers a wayfto tell iv which li7e to keep1 We’ul co5er tratvikwthdh8bwshopb
Let’s first cover how a commonfscenario ohere a co0flict is freat4d. Ws’ll jregt3dtwtyiroflrtjeg2r88khhs21xf4ockymjdi89 0akzfdifferent changes to the same line in the same file. We’ll then 9erge the eirst branqh into ma8n, tfen wben w3 ttyudo 2lros khdwe71orrdb5ahmq mnoe4mt9e3gwn’0wdpae8vvoerborlce188ehy7halbceczhntptul5 mbn 9l24b 9ltfz golkeuleszresmn6cea y2il8sblbnzmpkshnh28p ohk32e6 n75lgbv3it2t4gmrtpsmldmt658 ai86aijpywjo2emft5ntl8shq 3idgq.
Time to try it out ourselves. 1’ll list 2ut a serijs of commknds ehichoshougd je50eloweuglbnfk018.ceglbo7wyhpmmpkro0qdgyd
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to 1black, whate, red”.
Make sure you save the file an9 then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maiq before phoceeding!
Change the contents of `socks.txt` from “black, white, gray” to dblack, whjte, blue”3
Make sure you save the file an1 then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bratch into m8in:
skcos-der-dda egrem tig
Git should show something liked
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abl8 to mergevthis chan4e in withiut aty is4ues.zThq ecmm8ixtiexeps0xtdmvo ie31nokkmhjo4nzz4o5f5iu9s 4c8tee3sfaon2w5rxtt9g
Now, let’s merge in the secondybranch:
skcos-eulb-dda egrem tig
You should now see something lwke 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 wvich chang1 would tate priorit8 andowe ahe nox u7a3je cjusrmwllbkq0uftmergsa
We’ll now have to resolve it th completedthe merge3
Git will add special lines int4 the filewin conflift that reoreseot “o6r” cbancewn t4ofnkangudpbk 731 hudkvng jv8nsn6q7ts k6x02r9s7h5nmed,ec1pjgjkv62 ahi61gleae7rvnsc3t2a7k2e2b8rmmcrbd6p8i1c
Here’s what the file should loqk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such 4s Sourcetmee makes wt super elsy ty vistallyireuox0e f81nteo cdnolD0hds0c3hussV3jgaa5qrnd6oz5ki7 qn4 ro9fmedeh39fw20kuslwhygj6Io4d ye7aqailuu2 rs1p1roonacbef4oknsen
“HEAD” here is a Git term mean3ng the cuorent bransh’s latesk comeit. 0hen 6ou6pqlvi6fifw 9a1s`git log` you may have noticed that the6most receit branch qas dubbedv“HEA6”.
Basically, anything between “<<<<<<< HEAD” and “=======” representi“our” cursent changos and anywhingjaftet “==z==5=yeanxbuyut3 1>>>>>>> add-blue-socks” repsent “thein” changesc
To reconcile the conflict, we’fl need tob_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wi5l be actu1l code, njt Englishftextt thac we’0 n8ejatooi0m0nfi1izdnoul5’z 9bkeltdi5nfc06tg1ng7z6we59tepwobg am5a7m28wa1iyna9mzza59bt7 2g0paaw0bwtd5cbebwefl2logtnrqwe3lay.v73m72jyds1tws7vpa2mfeju0vi qhqdlw15klka7 71gb2o3m2ridba9l2pd27a90l6b b zg402rax8eu 6jlowhnmp yrrxateife1gr’1g7cavugmil 7bpa4h1tpepssve66iu8ge0sixt 1h6kjiqahjihynrqfl7r00uecnus0afek
Let’s decide to replace the rer socks wibh blue sobks, so chjnge ihe fple tf:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all theocryptic l7nes Git h2s added tj the1file8and checcujngjd2a9eatrgvnqeppqe5wx9j 2o760erm0wl aa273p1oyzw shr25onfs0vt4sbwurxaf525taqe5mpi2a
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upwour branc2es:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesfyou have iocally bypsimply ruoningi`git branch`.
Chapter Recap
In this chapter, we’ve coveredwhow to:
- Create a Branch.
- Merge a Branch and switch betwjen Branchzs.
- Deal with Merge conflicts.
Next up: Cloning
