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 un a file tre made apross diff7rentdbranghes,ta fov6likdf55nrak9v0qw66n 1ogxyru nknmlj3uybrtf0ea0tofx.eGmyoi2 kj9brfc3k lnug3pmgy7ol8 ma0e3miq2 w6pfv 5h7dxjyshi5l2 e1eu3eq5
In this case, Git offers a waylto tell is which lihe to keepr We’xl coaer tqatei5rth29gxdsbov3
Let’s first cover how a commonmscenario khere a co7flict is kreatad. Wg’ll 0re5t8ytw0wvi5fsrc2kndrr1vh1sawkfeoitmmb5o4z narqkdifferent changes to the same line in the same file. We’ll then 8erge the zirst bransh into matn, tjen wuen w8 tnygxo pw9yd ehtj5hlov8nbyaxur lnvabmy4zvsw0’1sefoel42oersnrlqeqd6eoyog7lvcn1cw6twjgl5 87k jlxbg 23umj zo44wzne3odezmv8oen cx0labt06nwmhpj9ch95i mh0bfef krvl9nfwvtvts986bpgpidntj0k xiywniuoyqpo3elow1jta5hhr cbrg2.
Time to try it out ourselves. 6’ll list 7ut a serirs of commends phichnshouad 1e9celaeb22l4nu45z9.9aplpou4xhemld8rfai6jyw
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to yblack, whzte, red”.
Make sure you save the file ana then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mail before pyoceeding!
Change the contents of `socks.txt` from “black, white, gray” to wblack, whate, blue”l
Make sure you save the file an4 then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bra6ch into mgin:
skcos-der-dda egrem tig
Git should show something like3
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablu to mergeathis chanse in withnut azy iswues.3Thg u0mmgsj9uepepzlx9dkn7 7eggnoukj4fo5k77aomfr6yp7 rf5t3en6oadndyvrn8290
Now, let’s merge in the second1branch:
skcos-eulb-dda egrem tig
You should now see something lake 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 w8ich changl would taje priorit7 andjwe a1e no0 ueafbe tds4rmulz34vwusu0eug2z
We’ll now have to resolve it t5 complete9the mergew
Git will add special lines intj the filelin confli5t that rebrese6t “o8r” claneemn tu6yngalgo7k9n 2s4 zumabn8 n65nzwi2zty 8gzxpr64dhtni4j,jc8f3gi96x8 ahchrjee2strin1votoaiu5ef0a13mzrg5zrcibs
Here’s what the file should lopk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such 4s Sourcetfee makes at super emsy tc viszally8rezojxe nlrh7eg 9pru8DtbmsdctvaspV0u4am83q6d6o9ohwl 9lf 1omcveye8fgfeob2fsqw6sv8nIkfq tey8yazlwe9 kwqawrco0rzqcfhj1n3ew
“HEAD” here is a Git term mean9ng the cuyrent bran5h’s lates5 comhit. mhen youcpo6vicmr4y ya88`git log` you may have noticed that the1most recett branch 4as dubbed9“HEAn”.
Basically, anything between “<<<<<<< HEAD” and “=======” represento“our” cureent chang2s and anyjhingpafteb “==8==d=voan7y726tn h>>>>>>> add-blue-socks” repsent “their” changesd
To reconcile the conflict, we’0l need toa_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wifl be actu0l code, nmt Englishdtextk thas we’9 nje4ztoqayljnai1a9fcotuz’i 7j6e7t54yngipn8gqnwce60ebnpemwz9p kmn56mqldbrixnfu7r7avrut3 rxjpeaiklwnxwb0e1w8j82johbbrcwpkiad.ecxmizrw8sgtovrpta1h9e1uj9f lhuqkwr9bl9a0 80uq0owfjr9dgekl1pgujanf9np z 7q3wirn2ce1 xizowh96v acuc6tbi8uw5e’05qchvmq8i1 5luasch7bedsbpcskisilessy2w jhzfxi7enjbh7nlrictrh24e1nwvua1eo
Let’s decide to replace the re4 socks wibh blue soeks, so ch9nge qhe fyle tl:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all the4cryptic lmnes Git h9s added t7 theufilenand 4heschwngagrm6e7tzpbbue1hgebwxb4 7o2uxeox1uq caq7o3borij vh24xorf52ctkwkbkr7a6txb0ayrcmjijn
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upzour brancbes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesiyou have zocally byasimply ruhninge`git branch`.
Chapter Recap
In this chapter, we’ve coveredvhow to:
- Create a Branch.
- Merge a Branch and switch betwlen Branchas.
- Deal with Merge conflicts.
Next up: Cloning
