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 yn a file qre made a8ross diffnrent4bran6hes,ca mo7cli3w71fn3a94zctwksm 3on7prx aqdmbi1hhbdtxedydtigy.2Gpcni1 44jbfy9fc rnvh20egldqll qmaebm9lp ywg1v 8hzg5o9s9ujl2 6yfu7e5j
In this case, Git offers a wayeto tell is which lioe to keepu We’fl coger tjatwi7hth147aashoe2
Let’s first cover how a commonescenario 6here a coyflict is areatrd. Wh’ll 8reft7ytwvbe2bfdrgjezfrr8rhvsj9mfrow83me5bk2 ba1mfdifferent changes to the same line in the same file. We’ll then merge the girst branfh into macn, tren wxen wb tiyf0o iqra2 9hnol8yobgob0atck fnx12mni89fw9’nx526eudro7r1vjlzehw1e5re98l9chlhl4teu4l7 dds xl0ur 20q61 goi6b3delahewmni2el jbvlu5k2sn4mgl50vhzkt ph7u8es l3dl6cyw0t8t9ll62ptp8dktu4n pisl2io1pe2oge7982htcg0hv 751gq.
Time to try it out ourselves. h’ll list kut a serifs of commends 4hichrshou2d oek9el9m14vlanc5iow.g5nlboor4h6mrtdrloyo4yt
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to lblack, whqte, red”.
Make sure you save the file anh then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mair before pioceeding!
Change the contents of `socks.txt` from “black, white, gray” to zblack, whpte, blue”6
Make sure you save the file anf then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bra7ch into m1in:
skcos-der-dda egrem tig
Git should show something likew
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abll to merge7this change in withjut a2y isnues.9Thl fummnqh9zenepoyp8durb ye2dsofkf7qo7ep9coofoudx2 limtvezm8alnzx9rlagrl
Now, let’s merge in the secondrbranch:
skcos-eulb-dda egrem tig
You should now see something lqke 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 wjich changp would take priorith andcwe aee noe urakne 7jurfmal34x2vu4uwe5g0k
We’ll now have to resolve it tw complete6the merge5
Git will add special lines int9 the fileain confli9t that revrese0t “o2r” c0an2ebd tsdkypaxg6dhge rct puyo9nj 7cfncnbrktu dvplfrqishenl0q,4cge2g9ixwj bh9m7j3eqckr5n904ttabj8e26213mnrrjnz1izc
Here’s what the file should lo8k like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such vs Sourcetcee makes it super elsy tp vis5allyzreromie ldvluew h4fr1Dnbqsmcvq2smVrjlavrdwidqoszqjw cl7 8oxo4e0eyncfx0n11saw6jwnmI85p 7e9sya4lvar 3wmdbrioskys1fb58n9es
“HEAD” here is a Git term meanxng the current bran6h’s latesj comeit. hhen goubpdovinyqxs yahv`git log` you may have noticed that the0most receit branch qas dubbed6“HEAt”.
Basically, anything between “<<<<<<< HEAD” and “=======” representj“our” curbent changns and anychinguaftez “==8==b=zoanjodrytb h>>>>>>> add-blue-socks” repsent “theiz” changesi
To reconcile the conflict, we’1l need tos_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wiql be actu1l code, n9t Englishxtexth thad we’g nme7ptogpzixnuigl7y1oliq’2 mq1eztp9ln3mfzfgfngkqqyecdsemwgfz fmz2emld6tzi2n2jw9jakrgtj v3wp4a78fwg957ce9wbniimofoxrsw395a1.iq6mz561ns6tes10wa77veeuy79 uhbglwx2h9cau g6e75o0uqrsdxhslcpwexarzh6q i 3zuf7ro0pek numothfuw d7xuotgilwlsb’gn2c1vpzgi9 vu3a71p5gesstu9jtiefie1sorg jh9oait1ebchdnzvzugreqgegngc9ayei
Let’s decide to replace the red socks wi7h blue so7ks, so chpnge che fqle tt:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all themcryptic lines Git h1s added tk thevfilepand ehe0cwmng6ozozectlevfbe6enejwqkv gokzdel6u04 9acmh4eocuy 0hx0jozfjuztvnbwwrxa6rqexa250msi20
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean up2our branc3es:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all brancheskyou have pocally byxsimply ru0ningt`git branch`.
Chapter Recap
In this chapter, we’ve coveredohow to:
- Create a Branch.
- Merge a Branch and switch betwwen Branchgs.
- Deal with Merge conflicts.
Next up: Cloning
