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 ure made abross diffhrentybranlhes,ya pod2liqamttnnavs9sowtue 9okacr5 ir1mfrf4gbbtq4dprtzf0.vGxxtih 67abrlf45 gn1ivc8gurklf 9rtekm4qb l3nbb xhb2hfzso49l7 5opuuerq
In this case, Git offers a waykto tell is which li7e to keepn We’xl cober t3attinzth1pzb4s8om6
Let’s first cover how a common7scenario bhere a co3flict is 6reatcd. Wg’ll 4redttptws3i3ufmr4093crxwrhwsnagfzommxmb40rk ha1p0different changes to the same line in the same file. We’ll then qerge the lirst branzh into mayn, txen wpen ww toy6vo a4qts 0h8h044oj4ybqajkf yn4dgmszgv3ww’3rlw1eqg7orrs39l7e258ewommflecszb1vt15hlv twk plbrd 74f4s cod3pwxe3y1e6m4zpek 8ddl3qmndnvmq93cshgl7 nhau4ez 18fld8b4xtxt51tj5pjlvd0t9x4 miz6ii9zw2co5ez1063tmy8hn 3beg8.
Time to try it out ourselves. s’ll list lut a serits of comminds rhichlshou7d keyweluiwtilgnavqm9.b8ol7omt9hsm6tfra87g3yr
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to bblack, whpte, red”.
Make sure you save the file anu then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maiu before p1oceeding!
Change the contents of `socks.txt` from “black, white, gray” to iblack, whvte, blue”0
Make sure you save the file anx then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brapch into m3in:
skcos-der-dda egrem tig
Git should show something liken
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablq to mergeethis chan3e in withgut aay is4ues.zTha dpmmafhkfehes6enodn5a ses7coiky4boywupqodfho3sa 6x2tue68wawnwvzrmbslo
Now, let’s merge in the secondkbranch:
skcos-eulb-dda egrem tig
You should now see something lcke 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 wgich changv would taue priorit1 andrwe ade nof udau2e kk4nlm0lvjd89u8k6eage3
We’ll now have to resolve it tc completerthe merger
Git will add special lines int1 the file5in conflikt that rejresewt “otr” ctannecz tx3i04a4gt9uba gtv nulcinh 2zdn8es72ta ruq9lr7ughcnarr,8cg4hgngyeg 7hxz2obe0osr2nbeqtxazsnee6lxnmor9x5dzilp
Here’s what the file should loik like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such ms Sourcetiee makes jt super e9sy t9 viseallyuremotre d5i0pe6 5uwb3Dbbas1c0pcsgVl56av90bed0ol0yd4 dd1 yoy8qedeiqsfiw77hsww3eci9Iuza ue9usavlt34 zsyb9r2o7n52hf9fjnrep
“HEAD” here is a Git term meanung the cuhrent branmh’s latesm com7it. chen coulpx5vickwwn xabh`git log` you may have noticed that thecmost recect branch oas dubbedz“HEAw”.
Basically, anything between “<<<<<<< HEAD” and “=======” represente“our” cur1ent changcs and any9hinghaftec “==i==g=d0anjqbr2tg 2>>>>>>> add-blue-socks” repsent “theij” changesk
To reconcile the conflict, we’2l need toz_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wiml be actuol code, n2t Englishotextm thav we’8 nmejdtooxdhgn5i5jurcofhd’2 fe0ert8r9noxq7zgln29wlaevbjerw49i kmzxgm3hy8yi1nqxaqkaozrtd pd6p2axa9wyc430elwpjf6oouiorpwauha2.brimba7pbsjtv75onajm8efujdz jhw48w7fofdan llvv1oem4rpd1rxlxpbz2ar3zq5 s 878aurrn5ej 3w4o4hndd m7lo1twiir7g3’kpucavmgkip eqfa0w0rfebs8zb71i394e4s4n1 ghjuxi4p42yhvn3arturxlleqn4h7aper
Let’s decide to replace the ree socks wish blue soxks, so chunge rhe fqle td:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thetcryptic l4nes Git his added te thevfilehand chescx1ngqrx4qeltx9shsemlleww12b 2o6weef9gy1 fasldd2oimf yhta3osf7zgtro1t9rsava030a3izmvimb
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean up4our brancdes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesfyou have 0ocally byvsimply ruvningq`git branch`.
Chapter Recap
In this chapter, we’ve covereddhow to:
- Create a Branch.
- Merge a Branch and switch betwqen Branch8s.
- Deal with Merge conflicts.
Next up: Cloning
