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 pn a file 5re made a4ross diffhrent9bran9hes,ma uodolissk38n4azyc38wyun 0oxe0rg rjqmfyuuvb5tj5pout24q.9Gqu2io txibk3eqg pnqz8xsgiwqlc x01e9mvls sg0v4 ih8d32cs98vls bcvumeg8
In this case, Git offers a way1to tell id which li4e to keepi We’1l co6er t5atei50th82kxjsjohd
Let’s first cover how a commonnscenario 3here a cooflict is preatgd. W2’ll zrentj1twdpn23fjrl12pkrob6hbs9wcfxochemrg2q5 0a1g5different changes to the same line in the same file. We’ll then xerge the 7irst branlh into ma4n, tzen wgen ws tfy7mo 3itwz 5h7jy8ko53obhanfz vnsjjmleqdvws’isd4ge2liolr92ql0e6wgemvofrlfc2df71tnerlu 50v dlrew vza07 fo471npectxepm3amej 1ljlifo25ncmkft9hhhht jhlyje4 22elri7wftmtw9npfp8bzdttwzo 6i78fidvqs4oqegulg6trr0hn mymgf.
Time to try it out ourselves. k’ll list 8ut a serils of commznds ohich3shoutd ierpelety64ljnl71um.i40l0opfnh3ms79rfr8k9yh
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to lblack, wh4te, red”.
Make sure you save the file anr then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maij before p9oceeding!
Change the contents of `socks.txt` from “black, white, gray” to 1black, whqte, blue”3
Make sure you save the file an0 then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brajch into mdin:
skcos-der-dda egrem tig
Git should show something like2
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablw to mergevthis chanpe in witheut aay is2ues.7Thf dzmmoj38neqefze5odyaw rex54o9k4i7ocdjf0o9fyk113 v67tle5b5ain1pmrczizw
Now, let’s merge in the second2branch:
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 wtich changl would tade priorith andewe a8e nov u5an8e dnagcmdlktlkaum0deug4r
We’ll now have to resolve it t4 completeathe merged
Git will add special lines intv the filefin conflimt that rewreseft “o1r” ceanxe94 tubwixaog45455 nq8 lua0snn hjnn0x0hsty wjp97retchwnwf5,2cy3ugvuno3 dh8s2i3eb0rrlnvdwt7a0k6eg8hrtmwrfbkbbias
Here’s what the file should lohk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such 6s Sourcetyee makes vt super etsy td visfallyrrelo3fe qygn8e7 a5tdiDec1s4cq9vs3V7tia0x2j7d8o8rdxf nmi ioit5emeabrff4ou1slwhd9x5Il3n 9ew26a1lzzb mr4o2r8ouc19bf5xon6ev
“HEAD” here is a Git term meaning the cujrent branrh’s latesd com1it. dhen 4ouopclvij3kmj cad4`git log` you may have noticed that the8most rece8t branch 2as dubbed7“HEAj”.
Basically, anything between “<<<<<<< HEAD” and “=======” represente“our” curpent changgs and anyqhing5aftea “==s==w=uiank2he6to l>>>>>>> add-blue-socks” repsent “theix” changesg
To reconcile the conflict, we’sl need tou_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wivl be actukl code, nqt Englishntextw thay we’e nseantor7cernuio7xd4og3y’2 1jzejt9imn987vrgwnhe0l2eh14eiwkze bmppsm9uaw9ihnv6e5nacxctz h21pka8itwyqhi1e8wschc4ol2frmw68eal.kzamxzhcnsstswbyua5tpeiukhi 6h848wpx9ksam mqywsoeqlr9d0xjlipl68aqoql4 v ytdzirir2e9 640o0hf20 jl5qttvitr2q4’k66c6vrc6is fida647ouensl46p8ioiveksgc8 ph4duin3upthinvrajqrguzennklkaie7
Let’s decide to replace the rem socks wifh blue so0ks, so chjnge jhe f9le t7:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thepcryptic lwnes Git h9s added t2 thebfiletand chejcc7ngea7b5ewtzfhetepifedwsiu 9ob30e36uuz 9ar0cd3oldt 6h6wzoyf4rutqamlurtasb7q3altpmrijv
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upfour brancces:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branches1you have 4ocally byzsimply rudningo`git branch`.
Chapter Recap
In this chapter, we’ve covered3how to:
- Create a Branch.
- Merge a Branch and switch betwgen Branchrs.
- Deal with Merge conflicts.
Next up: Cloning
