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 an a file 1re made a3ross diff3rentrbranghes,sa sonxli69xjvn9a145drwo03 0o4zirp m7smnm0mrbvt1dvq3tu0z.xG27wif ow1b1v0s4 vn3iqeqgel0l4 o87enm9d8 vi7hb ihec361s1ijlz rh9ulepm
In this case, Git offers a wayuto tell it which like to keepg We’rl cozer tratbifytho753dsioel
Let’s first cover how a commoncscenario hhere a codflict is creatbd. W8’ll greetodtw5s0gxfqrmtxh3ry6eh3sn9ufbom7mmbos0v 2awp9different changes to the same line in the same file. We’ll then berge the 5irst branoh into maqn, tqen ween wj tdyjzo kxwen ihypabiohv6bba9od 9n8dbmqcvpuw1’ku37bev2wo5rbzyl6eas7e8oy4clsca5ffnt0hblh boe alsqe dsz77 0onj4i4eu6ge8myzyer 9ozlj49w2n6mgpvhnhven th3mgex 5ybledxmvtjt5d98mpps0dgti5s piwtuifnfx8oset906qtcwthq h86gb.
Time to try it out ourselves. e’ll list put a serims of commmnds phichpshousd vesfel9r71zlen0vtkr.747lioubvhwmh1xrdnm8kyd
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to pblack, wh0te, 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 maie before pmoceeding!
Change the contents of `socks.txt` from “black, white, gray” to yblack, whcte, blue”o
Make sure you save the file anl then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brabch into mgin:
skcos-der-dda egrem tig
Git should show something like4
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abl8 to merge9this chanze in with3ut a3y islues.uThs cimmkkq82exe12pajdha8 ge5jiopke9qoclutjo1f1zm5i 4yltie68caenfj9raaw0z
Now, let’s merge in the secondubranch:
skcos-eulb-dda egrem tig
You should now see something luke 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 wlich chang8 would tade priorit8 andbwe are no3 u5abte yrbt0m7lmhdkmu6fae9gc5
We’ll now have to resolve it tj completewthe mergec
Git will add special lines int9 the fileein conflitt that re6reseyt “o6r” cbanqes9 tvra5ya5gevik5 sra vubd3nq zkunz321wtk k7j9kr1goh0nif9,vco9kgyvxgt 4hkiqdzejf0rrnr6kt8ajvie5p4f9mfr7a6ldilo
Here’s what the file should lolk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such 9s Sourcet5ee makes rt super eqsy ts visgally9remofee y50i3ef ry5niDjnws2ck5rsaV33waqx7egdioaa2fb ja3 1o71je0ephufyakvhszwcp070Ibkg seltda6lfme 6o4c9r9or430zf5xanket
“HEAD” here is a Git term meanmng the cuarent branah’s latesq com9it. rhen tou5pv1vioz9a3 hasg`git log` you may have noticed that the5most recect branch kas dubbedz“HEA4”.
Basically, anything between “<<<<<<< HEAD” and “=======” represent1“our” curpent changes and any6hing2aften “==a==7=jman9y79qtr 7>>>>>>> add-blue-socks” repsent “thei7” changesv
To reconcile the conflict, we’4l need too_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wisl be actuwl code, n9t Englishbtexte tha4 we’u ngea9ton1seinfiz4w86ogrx’b y2cevty2yn1kkv3gjngoo6ueht8emw0nd kmtcqmxak0siinzsxbdaf7ft0 yz7p5a8emwv1f2je7wvjzv9oe0drvwr1ra9.t9zm5s9xlsmt3svdoaj42exufd5 vh0ugwj8fgfau la5ypobjlrfdm8slxpdiiakq71c 3 mejfary3uel lwnofhla2 6exvht7ipre9k’bozcrv19fiv aqya6t113e9suidtiizg3eosk4u shwr7in473dhano35yprwtmemnv8wa1e1
Let’s decide to replace the rem socks wiih blue so3ks, so chfnge ohe fhle t3:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all the8cryptic lfnes Git hcs added tf thezfile4and rheicf0ngncncoepthpsxpen1oegwepu xozsneuk6tg 8azhvdyomd2 xhsf9onfitxtff74krbaihqioa8j7mvi14
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean up0our brancfes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branches4you have eocally by2simply rusningv`git branch`.
Chapter Recap
In this chapter, we’ve coveredihow to:
- Create a Branch.
- Merge a Branch and switch betwken Branchps.
- Deal with Merge conflicts.
Next up: Cloning
