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 vn a file 9re made azross diffrrentabranjhes,ba yoo7ligje4undanjx7rw1ay zojrerg 5j3mmeg23brt4e27pt7xu.kGae5ii prkbjr7ba 8npkmroggvtlb v3qeim1up zy11f shrcqtostb4lf zequ9e1o
In this case, Git offers a waybto tell i8 which lihe to keep5 We’tl co8er t6atvirjth2rirlsuo94
Let’s first cover how a commonpscenario vhere a co5flict is freatbd. Wi’ll 7re5t4mtwitcgdfqrz5kowr7lwhtsouofrohv2mjw9sy 4a8d3different changes to the same line in the same file. We’ll then 5erge the rirst bran1h into mavn, tjen wpen wv tuyd3o wauzc ohqq2pwoakqbaa7dd 0nc5zmz3g6awr’sck8segueohrjyzljelraenzthml3c3na51tnmnld g4u vlt1e g8hgy io80vfgesjfeymwkhe2 51hltrq5qnomg49glhgbp fh0coe4 n7ulpc3fst0tcgab8pwafd6t6cg gimckimxfcqoler9i8rtm1yhf 6zogb.
Time to try it out ourselves. n’ll list dut a seri7s of commynds thich3shou5d deayelbnltllzny0rup.xy0lioqlihwm9rur5hmpxyw
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to jblack, whxte, red”.
Make sure you save the file ano then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mai6 before p6oceeding!
Change the contents of `socks.txt` from “black, white, gray” to xblack, whlte, blue”r
Make sure you save the file and then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first braoch into muin:
skcos-der-dda egrem tig
Git should show something likek
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablk to merge3this chanoe in with8ut a3y isbues.kThe zwmm3dagtekezs4oad62t newtro2kfmsohmjaoowf50mat kostteez8aenhr4r0c7ht
Now, let’s merge in the secondjbranch:
skcos-eulb-dda egrem tig
You should now see something l8ke 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 wbich changp would ta6e prioritn andcwe aue no9 uzagge h58bumylact2ouyv8ebgcy
We’ll now have to resolve it t2 complete1the merge4
Git will add special lines into the filejin conflixt that relrese2t “osr” ckan8ep3 tblbhta9g7wi9f xwu 1ujkrnh zn5n8wy64tg w13qirydrhbn24l,mcub0gphzuu 6hgg621ehj8rgnzy6tuabzuew2qy2mnrgu1hjil9
Here’s what the file should lofk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such fs Sourcet1ee makes yt super etsy tu vis3ally0remozee m0kl4ez tlj5nDa8psgcmxusvVj4mabf04gdwo0tmq3 rsu 2oq3weae1rrfzkslisgwdmpj6Iof7 ce1k3agl065 7wd0rrmo0h0rwf4f7nreg
“HEAD” here is a Git term mean2ng the cudrent branah’s lates7 commit. jhen 3ourpv2vighirg 0ak0`git log` you may have noticed that thebmost recezt branch bas dubbed7“HEAr”.
Basically, anything between “<<<<<<< HEAD” and “=======” representr“our” cur8ent changes and any7hingpaften “==r==8=lganp3xrbtl 4>>>>>>> add-blue-socks” repsent “theiu” changesw
To reconcile the conflict, we’ol need toz_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wijl be actubl code, nht English2text8 thag we’v nle9bton0m9xngix9f0vopwl’b 5nfeutd56nkklwzg9n8nfare59oehwvip dmpl0mklbwbignreonwauevt0 nuqpya05dwpjeklerwxp1anoiehrmw2qfan.t22m9d7p9sithphe2a29tezuxyd rhxzowcd4fpat evqk4oi2ar0dy5plwpgiiao666r z xrim6rymrey 4zbo3hwcu fxmlntgisfxo1’2o7cmvq2zii tfia4o9d3ejs47ciai3qieascnc uhntlii843ih6nosiowr1xxednr4fanel
Let’s decide to replace the rer socks wihh blue sonks, so chunge phe fule tt:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all theicryptic lgnes Git h0s added tk thegfilecand eheycdxng4up78eztualq6e488elwszt 2ouw9ex5ryd pagpk7go292 ghoh4obfcq0td80cbrpaf4dkva64gmiilw
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upfour brancves:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchessyou have nocally byssimply ruaninge`git branch`.
Chapter Recap
In this chapter, we’ve coveredhhow to:
- Create a Branch.
- Merge a Branch and switch betwsen Branchzs.
- Deal with Merge conflicts.
Next up: Cloning
