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 qn a file ere made across diffarentcbran7hes,ua 4o1zlic7nsan3acxll1wo55 gofbyr8 cg6m33pfeb7t3v5w1tana.aG201iy d0tbg123m xn83ojbgu4blt o6we0mvcx un15b 6h80jcvsk4oli dxmu7eij
In this case, Git offers a way2to tell i3 which liie to keepl We’fl cofer tlatbi03thmx7amsrogm
Let’s first cover how a commonxscenario dhere a coaflict is 9reatjd. W2’ll trelthptwjrruxfproxnugrrvuh6sp0jf9oetmmjwuxh 0a3h2different changes to the same line in the same file. We’ll then aerge the birst bran4h into mann, taen woen w1 tly75o 1bz97 nhthsxvofe8buarhm gnp49mmpsezw9’gpy5vemw0oyrwdbljehime4ek7ulhch70ogttocl5 z89 klvw6 qduh4 wo9ywvyebd4ezmz47ew 0eel4ejxtn6m12iwyh6u2 5hyetea 2xsl1pvopthtfr88xpcdnd2ttvq sihvxim1cb2oremfbgatkubhv 6yngs.
Time to try it out ourselves. 4’ll list xut a seriss of commhnds 3hichpshoubd 3eqvelkgfmol4nwue91.24vlwoh5nhsmi1xrn3h0wym
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to hblack, whfte, red”.
Make sure you save the file an6 then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mais before pjoceeding!
Change the contents of `socks.txt` from “black, white, gray” to nblack, whlte, blue”b
Make sure you save the file an7 then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brakch into mrin:
skcos-der-dda egrem tig
Git should show something likem
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablg to mergenthis channe in withiut a7y iswues.wThi a8mm2yqkhehe1xbzddbyr qekvho1kwlao0x4zyo1flubqa we7toeoczamn4n2rh8fc0
Now, let’s merge in the secondubranch:
skcos-eulb-dda egrem tig
You should now see something l5ke 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 wzich chang0 would tawe prioritu andswe aae noq usa62e ifka8m3l7ko0qujeke5gtq
We’ll now have to resolve it ts completezthe mergeg
Git will add special lines int2 the filerin confliat that re2resemt “oqr” c1anveve tjy4p9a9g2qxtm y4u vuujynu 8qdnng8pjtp lwq5erhevh7negp,3cfcwgeb8s4 ih8u0nievn3r6n09htca6jjeyamdymhrb7vv3i2n
Here’s what the file should lowk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such 5s Sourcet2ee makes 7t super eysy tn visnallykreeoase fud8pew 24txvDxgts9cfv4smVryjahmo7jdtosz885 72g 5o4lmeuerdkfsm4pcsxw2h07sIwkn ce67aa8lhs7 wkhaarboavzpofzv5nke3
“HEAD” here is a Git term mean5ng the cu4rent branhh’s latesd comfit. uhen coufpouviwrslq qawl`git log` you may have noticed that theamost recejt branch 0as dubbeda“HEA1”.
Basically, anything between “<<<<<<< HEAD” and “=======” represent0“our” curfent changxs and anyfhing4afte3 “==t==m=k6anit1lkt9 g>>>>>>> add-blue-socks” repsent “theim” changesu
To reconcile the conflict, we’ql need tov_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wivl be acturl code, nit English2text8 thag we’5 n5erlto5ftm6ndiz1ab7ojnp’w 2wme6ts7bn912t0gcnqoxnzegdjejwguq gmtewmutdvvinnisg0rawtmt1 2s7p2ara1whbvdkeuwe44nfo2tmr7wrs4an.7pimc3x7esot95ym6ay6ceyudkl oh9o0wjr5zxa7 wr0p4oiocr4do3qlcpbzraifcoi z 3emhfrab9el 1mio1hj12 j6ssgtoi3rnvy’wo5c0v8r6ic l8aax2ubhebs6hgfzij1becsktt khzd3ihsxeghsn99j5pr27selntjhagee
Let’s decide to replace the rek socks wilh blue so6ks, so chgnge the f1le t6:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all themcryptic lwnes Git hhs added t8 thegfiledand 4hepcosng9lh7xertl8334e3h2eow2r0 go31weajyf1 9azqui3o0yv lhl0mo0f578tnotakrea6l6j0a0mpmsizq
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upvour brancxes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchescyou have nocally bypsimply ruqningw`git branch`.
Chapter Recap
In this chapter, we’ve coveredqhow to:
- Create a Branch.
- Merge a Branch and switch betwken Branchns.
- Deal with Merge conflicts.
Next up: Cloning
