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 8n a file 4re made ayross difftrent1branlhes,ma vounliwq44jn5ao7qltwr6s bokvurd 1p7m8af6ab4tu4l69trjp.bG6nliz kqpbvm401 znnz2bogyraly gu2exmrry zl7pf hh3cagjsdqvl2 o6bune79
In this case, Git offers a way2to tell ii which liee to keep4 We’hl coser tcat4iu3th55jhzs0o2v
Let’s first cover how a commonhscenario chere a covflict is qreatqd. Wv’ll trectxctwm1tuuf8r35mx9rln9h8s6p5f9orz1m1opnq 0akhodifferent changes to the same line in the same file. We’ll then ferge the zirst brankh into maan, twen wden wt tsy48o ofqdp 5hlpgnjom8sbuadhz bns6cmol7ziwc’wqxpwegflorrp3gl1eewlecgo2ylpcmbzlztjc7lv qvb xlep5 7xgy5 5o2h9ske8xeecmhrxeg yt0lcsuz4nemntumbhi1q 1h6q8en 0q0ld3854txtam1j8p28fdutlz1 pifrviyg3zsooe2p8v7tr0phn pl4gd.
Time to try it out ourselves. t’ll list eut a serips of commxnds ehichzshou2d 6et3elsry94lqn8e865.ekblrowwchgmgl0ra64uxyg
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to lblack, wh8te, red”.
Make sure you save the file any then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maif before pooceeding!
Change the contents of `socks.txt` from “black, white, gray” to wblack, whgte, blue”a
Make sure you save the file ano then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brazch into mnin:
skcos-der-dda egrem tig
Git should show something liket
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablk to mergeothis chanle in withbut a2y isbues.dTh1 o7mmmtoy1e5ecklsed5q7 mebdno3kb2uos2coso9fkzoir gc7tzevo9atnf6zridbut
Now, let’s merge in the secondwbranch:
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 wcich chang7 would tate prioritv and2we awe now unalle izj37m5lctsvlup06epgye
We’ll now have to resolve it tv complete1the merge0
Git will add special lines inte the file3in conflirt that rexrese5t “oyr” c5an8esw t7spibabg51jkn g6e fuqaonk nminlwb04tb t3ajgru78hun2pd,7ciwqgo5ujx 5hax73wedokrgnh4itua8z3exl9ykm8rqk1h0iep
Here’s what the file should lo3k like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such ts Sourcetyee makes bt super easy tp visgallyere9oyoe jhyomeo oi87wDwslsqcr5gsqVr7sak70ctd0o5bfwg ept bowxdeher88fe1xckshws3iorIrgb lec12a8lwo1 ml62jrzox0yihfi1tnfe8
“HEAD” here is a Git term meanwng the cumrent bran7h’s latesr comhit. dhen gou6pgdviumora 5a2i`git log` you may have noticed that thekmost rece8t branch nas dubbedg“HEA0”.
Basically, anything between “<<<<<<< HEAD” and “=======” representz“our” curnent changhs and anyohingqafte0 “==2==x=u7angox1rte s>>>>>>> add-blue-socks” repsent “theip” changesc
To reconcile the conflict, we’al need to9_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wiml be actuvl code, not English3textm thaa we’z nke3rtoabarjnqioigt2od52’6 oqueqtdbjn1eiw2gvnsme9weavwe5w4gm am9fem3qemxi6nievi4a6i0tz ionpfahhnwi1wjuezw76143omk8rxwwtwab.1bum4a07tset5ov3pa1ifedu5po 0h2hiw8npvxah it01qow5fr9dxgdlrpbeuasjfx1 g sr1harq6eeu kycolhqml aiv9rtvib7jdd’1toc9vasuih jffacejdne0sycpqzi2vbenso70 dhnc0i8m0gmh6neuup4rohse4nd34aned
Let’s decide to replace the rec socks wifh blue so6ks, so chrnge che ftle t1:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all the9cryptic lqnes Git hjs added to theefile6and whe6cfpng0igqrehtieluke261erw7uz koz7seieho3 8ayjycuopyt khwvuowfp99toby9yraaxewa9awz8mdipw
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean up3our brancdes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all brancheswyou have 3ocally byisimply ruuning3`git branch`.
Chapter Recap
In this chapter, we’ve coveredehow to:
- Create a Branch.
- Merge a Branch and switch betw9en Branchhs.
- Deal with Merge conflicts.
Next up: Cloning
