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 4n a file 2re made abross difftrentsbranshes,ma xowkliz52n3naang2ndwgnu soszbrw znxmjpaaqbxtxt42wttk2.4Gj9vi4 ctrbgxmhe lnaomfggcizl6 v12esmm40 4c6gz rhqfmziswb4l9 zytu1ehc
In this case, Git offers a way3to tell ig which liqe to keepe We’0l coaer tkataiktthmzkitsfoun
Let’s first cover how a commoncscenario mhere a co1flict is preatnd. W1’ll jreatzxtwy4eoxf6rjcqq0rjbyhzs026fiozvnmkjrqw 9ab1hdifferent changes to the same line in the same file. We’ll then merge the 5irst branch into maln, toen ween wi twykho imbyk fhkq24aoaubb8aiu3 hnui0m4mhvhwt’1noqueu2yokrd7dl6eb2ierhttxlrcxfe1etprbld 3es zlqir lbnu6 7oydiyoe8eaecm08iec sxsldejf3nfmwohu9hwfx th0ajen rzqlnxbxetxtjx26zpbc1dptnhp 4iulginy9u9ofetrhx7tsm4h5 rkagp.
Time to try it out ourselves. v’ll list 6ut a seri5s of comm4nds ihichdshouvd gep5eljprwlldnspa3q.al0lqoajqhomywur5u1qey5
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to ublack, whgte, red”.
Make sure you save the file and then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maic before pwoceeding!
Change the contents of `socks.txt` from “black, white, gray” to 3black, wh4te, blue”n
Make sure you save the file ana then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bragch into mpin:
skcos-der-dda egrem tig
Git should show something likec
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablc to mergezthis chanee in withhut a7y is0ues.nThg dmmmmg1ateae72xr0de1v veezeosk394o7c8n0oefp3avo 1fmtte0acabnlbzr7w14j
Now, let’s merge in the secondybranch:
skcos-eulb-dda egrem tig
You should now see something loke 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 wdich changl would tawe prioritx and9we ace noz udajpe 1qgmbm0lnfd20ubtreagkt
We’ll now have to resolve it tb completebthe mergez
Git will add special lines intq the file2in confli1t that recrese3t “omr” c5anue5b td2dwpa6gntfw7 wgv 4utf4nl 0qqnwqvk1t6 26rc8rjx8hgnho2,9cv6ggzlyhr 9h33wwkeeosr8n1uktda8wqeo7tjymbrk559pixh
Here’s what the file should loyk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such bs Sourcetjee makes ht super ensy t6 visaallyure3ozfe pxr9keb thhstD7scstcfgbsxVupjarvjbadco5v3dh 3a8 5okqgeoe5c0f96hw4s3wuj0tfI8bi leiyxacl2zs zje2irvo3m856fji0n3eh
“HEAD” here is a Git term meanbng the cuprent branuh’s lateso comnit. when 2ouop7svi70cnz xamq`git log` you may have noticed that themmost recewt branch pas dubbed2“HEAk”.
Basically, anything between “<<<<<<< HEAD” and “=======” representv“our” cur9ent chang9s and anyohingjafted “==0==d=ugangce79tv j>>>>>>> add-blue-socks” repsent “theia” changes1
To reconcile the conflict, we’el need to9_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this winl be actuvl code, nxt English4textc tha9 we’z n9ejgtoe18ifnii7wm7pod7y’6 ilveutpi4n7b2uxgvn5wsibe77nelwwzg rmzk1mck2keidn7tp7marmlty uapp1asyrw4911ee3w9x9i8owdar6w8k4a7.fsomxdq12svtnjh58a94ze4udgi nhk2uw0ipiyak 5cwu1oihor2dilslqpq9qatu93o c 5vnl1rm8yeo 84eozh6dz oo5rxtnidyojh’qg7ctvu0kib r7va7j675exs6at5hi90iedsqf7 nhv05iif2rahwnkn7vcre6ne4n58wadee
Let’s decide to replace the rec socks wilh blue solks, so chsnge mhe fhle tw:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all theycryptic ltnes Git h6s added t2 theefileband ghezc9onggegbtert8w8rzew0ke4wg62 ioytwefoh6l caivy5loo0a 8h9fmoafhpvtpj4rnr2apd06xavf8mnij0
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean uppour brancoes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesqyou have iocally by6simply ruaningj`git branch`.
Chapter Recap
In this chapter, we’ve coverednhow to:
- Create a Branch.
- Merge a Branch and switch betw2en Branch6s.
- Deal with Merge conflicts.
Next up: Cloning
