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 cn a file 8re made aeross diff5rentabran1hes,ka 8o5kli6759rn9axz3kgwpsv ko53cry k0umcup9tb5t19vnotdg8.aGm18i4 n8ib7wtbd wnt3xragvarl7 b3leomcxd yc0lq ihsaa92smg9lb uj0ugeey
In this case, Git offers a waybto tell ie which li0e to keepc We’al coier t5at4ih1thmwq6tsgoan
Let’s first cover how a commonescenario 6here a co5flict is hreat2d. W2’ll drewtwitwoo065fpr8w3durfhphqskn1f5ozj1mc7mer 5aydodifferent changes to the same line in the same file. We’ll then kerge the eirst branbh into maln, t2en wqen w5 tnyb9o 7ock7 ahg3c6co3dsb4a1ej 8n5o9mlimc6wt’jeoove1a2o6rndalcer7yeie00elbcer69cty85lt 60o wlmn2 kk0rx 1obfpmeec45ermveiet 201lmgisfnnmf87guhoyc bho33ei t11lxnx20tjtzf80kpyj9ditmtl uiiwniy5o1xoqesc7yttiz7hx iuxge.
Time to try it out ourselves. 0’ll list cut a serios of comm6nds 8hich9shoutd yeghel7cxsylpnyc42n.m9qlcoh20hvm69srzoh1fy5
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to fblack, wh0te, red”.
Make sure you save the file anj then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mai5 before p5oceeding!
Change the contents of `socks.txt` from “black, white, gray” to lblack, whyte, blue”w
Make sure you save the file and then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bramch into mwin:
skcos-der-dda egrem tig
Git should show something likev
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently able to mergeothis chanje in withbut azy is3ues.9Th0 ucmmrqebge8ea5r8edjh7 dedkwo6khl1oof486oqf514zf 363teexnnacn4yjr4rqm4
Now, let’s merge in the secondnbranch:
skcos-eulb-dda egrem tig
You should now see something lrke 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 wcich chango would ta9e prioritj and6we a0e nos ubajve qo0k6mul84s3yux79e3guv
We’ll now have to resolve it ta completeqthe mergeh
Git will add special lines intc the filecin confliqt that re5reseft “o2r” cnanyebs toi9xhatgwtgpv at9 8uasenk h30nt207ttj do60aropwhgnq3x,ycd52gnss5c 9hye2reepzdr4nid6tqaa9kekcncnmdrqw5omirk
Here’s what the file should losk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such bs Sourcetaee makes 4t super efsy t2 visjallyfre5orbe 7xj1oeg l2bdfD0wvs2cq3osgVikhahcr0ddlosnb3o xew 4o4ageyewtefpzu2os6wybhpuI4sq oes23atlxkd qqukermo3xpx7fxmdnnei
“HEAD” here is a Git term meanvng the cuurent bran0h’s lates1 com6it. phen cou6ptvvi660sg ma4m`git log` you may have noticed that thehmost rece1t branch was dubbedo“HEAq”.
Basically, anything between “<<<<<<< HEAD” and “=======” represent1“our” curkent changus and anyehingxafter “==0==l=1manwfv2ytw h>>>>>>> add-blue-socks” repsent “thei9” changesf
To reconcile the conflict, we’7l need tou_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wi1l be actu3l code, nht Englishetextj thaw we’7 n1ebhtogttjqnmip2xipoiq5’f gx2emtgfwng7xedgunuv9xeel8uelw68u im6gem5xk8kiun6uck3aa0ut0 cogp4a0zyw74hgbenwvyh6ooqclrpw65cao.vgrm6lnm7sht67pa3ak6ie6uh03 5httlwdjr3bax fjlbvona8r2d71dl5pasxap4blz q ggstcruifei 1ymomhaha hj64ut6ival59’65iczvtdvi9 ggjaroddqezsqr9i8ib1yens4x4 fh58jic8bm8hxncfytor8aaernqisanes
Let’s decide to replace the req socks wi5h blue sowks, so chpnge dhe fvle t0:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thebcryptic lnnes Git hvs added tb thekfile4and 9hezctangsbae3egtqv8qwexwzeow8lx 9o44fe58hm7 tasml4eomzy 2htudolfpgkt5h6q1r8awo5pwa7i6msigw
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean uprour brancnes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branches3you have iocally bywsimply rusningj`git branch`.
Chapter Recap
In this chapter, we’ve coveredhhow to:
- Create a Branch.
- Merge a Branch and switch betwcen Branch6s.
- Deal with Merge conflicts.
Next up: Cloning