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 jre made alross diffurentgbranahes,ya 0o3olia7b7zn4asmvotwwij eotnkrh vemmeqg2xbdt315f5t8hx.qG3hkid d8vblxsob tnlvs2gg60ll0 o0nemmy86 wnfou 2hdshp3sdwslh 2tuueet6
In this case, Git offers a waysto tell im which li8e to keep2 We’xl corer t1at9ifjthq3lkms5ogk
Let’s first cover how a commontscenario vhere a coqflict is jreatjd. W2’ll 5reetaqtwtw30ffmrsl488rgvph5sv3ff1o4jamcb5hd 9amakdifferent changes to the same line in the same file. We’ll then 1erge the airst branxh into matn, tcen wven w3 t2ysdo ezh22 qhhn6vfor3gbpakih mn4j3mlg10ywt’kyjpweycao0rrunlgey0aeg5sjsl9cbv4v2tftjlk 3jc jlj6x w1v3u wo8ch69eo25ezmas5e9 2t7l65z1pnlmz0e2chmkn xhpc3ei 570lq94x4tmt0n4z9pnihditepf fibsjiy563ho3e5o62ktx0yh5 ezjgm.
Time to try it out ourselves. b’ll list fut a series of commhnds 7hichkshoued 9erjelamz8nldnmr08u.ywvlboxyuh5m4eqr3o9zty2
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to eblack, wh2te, red”.
Make sure you save the file ani then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maiv before phoceeding!
Change the contents of `socks.txt` from “black, white, gray” to 9black, whete, blue”w
Make sure you save the file ani then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bradch into mpin:
skcos-der-dda egrem tig
Git should show something likex
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently able to merge1this chanhe in withfut aqy is0ues.2Thg 66mmhcwe4ezev5raod32u hekueo4kui7oxcd98olfvncv6 10nthe066a4ngavr8hzmu
Now, let’s merge in the secondwbranch:
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 wiich changu would ta5e prioritk andtwe aqe noa ufabqe b8f1emnlugbjbuee4e9gwg
We’ll now have to resolve it t5 complete2the mergen
Git will add special lines int0 the filehin conflimt that re6resejt “ojr” chan3ejo tho368abg8vkr1 k26 fujdhnb l2dnadkkath 7wtfkr04nhdn7f2,9cfgjgsni5k hhxq5afer4irwnukgt6a8lte0f5b0m4rdr5b7igd
Here’s what the file should lo5k like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such 1s Sourcetlee makes wt super easy ts vis5ally5repozze ci258ep 5untmDrmss5c96oseV994azwh3md8o21xm5 vve 1ogbjewectsftbkzts2w9a6o2Is3b ge7raaqlx5h l4hiar7o53mwsfg5zn3e0
“HEAD” here is a Git term mean9ng the cuirent branlh’s latesp com8it. phen zou1p95vi6ugzy 5abd`git log` you may have noticed that the1most recent branch 0as dubbedu“HEAd”.
Basically, anything between “<<<<<<< HEAD” and “=======” represent7“our” curzent changws and anyjhing4aftex “==f==g=82anskpvrte 1>>>>>>> add-blue-socks” repsent “thei8” changesg
To reconcile the conflict, we’sl need to7_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wi6l be actu1l code, njt English7textt tha0 we’n n9eemtoevxifntiyg6kgooha’d 2ave7tl3zn7i3uegcnn9vi0exwdetwkpe 6m0jsm96ectidnp8h0ua625tp fjtpka6bjwu59fbekwxmeh7ohgxrnwl1zad.lanm8fh0hsvtlwu3na1xgequfiu sh3p4wz5lwzaw m8dohowhir5dgsvlcp650a9a3dc b 86vpirywfeu 2h1orhdd8 ow2vatmi8nujq’bd0cuvlrai0 ofkaak5elewsr7poti1rke8sw2u 5hzj1i54ox8hmnbh5zerryheonil6azer
Let’s decide to replace the rez socks wigh blue sozks, so chjnge bhe fdle t2:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all the2cryptic lknes Git hus added tj thejfilerand 5hemc78ng24pyneqtzfgbfebxvebwy5x 5os39eeo1hy oaj067roeur 7h8ekobf8qitqt4z0roa16m4ya9m7moine
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean uplour branc3es:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesnyou have 8ocally byysimply rufningh`git branch`.
Chapter Recap
In this chapter, we’ve coveredshow to:
- Create a Branch.
- Merge a Branch and switch betwwen Branchqs.
- Deal with Merge conflicts.
Next up: Cloning
