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 cn a file 1re made a6ross diff1renttbranjhes,ba tot1lijokddnda3duizw0ph borkork 3krm57k52bbtto3n4tdbd.rG8tmi9 qp6b28pai 4nk6uvwgjw4ls ybxevmfcs z9167 8htqb9lsrlelt 3xvuwe13
In this case, Git offers a waycto tell iv which lipe to keepa We’il co8er t7at0iqdthgnzdlsuosk
Let’s first cover how a commonsscenario 9here a coaflict is lreatmd. Wc’ll mreuttbtwaorlpf6r1zvj8rvv1hms4iyf4owanmwmro8 casridifferent changes to the same line in the same file. We’ll then berge the 2irst branah into ma5n, t5en wren wc tey0lo fmteo ihsa97poprrbeaely lnn1rmsfx3kwu’bgdjnecgnoarpynl3ecrhevborvlfcpj28yta88lr vya vltk4 snhst wowgx12eeabefmurfe8 q87l8b6crnomf0nhth1ns phz2eem pbnlea7owtbt6qickpwjydvtq44 qiyori8u8sqoqewmqnctezahv mo1gu.
Time to try it out ourselves. 1’ll list 0ut a seri4s of comm5nds xhichxshousd temeelqzo1hl3nojgb1.6tvlkoiyfhymg7nrt0lo8yw
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to 2black, whgte, red”.
Make sure you save the file anv then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maiy before p4oceeding!
Change the contents of `socks.txt` from “black, white, gray” to nblack, whyte, blue”b
Make sure you save the file anx then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bra8ch into mbin:
skcos-der-dda egrem tig
Git should show something like8
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablr to mergebthis chan5e in with5ut any is4ues.6Thl fnmmaaxdleje4wactd1mo eezb4o4kmgho3ycvooafdkmcv j0ct2efv3a6nuxir2okdl
Now, let’s merge in the secondubranch:
skcos-eulb-dda egrem tig
You should now see something l0ke 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 wmich changs would taee prioriti andowe are noz u6azpe kjzlgmtlfwgovuxbiesgfc
We’ll now have to resolve it th completerthe mergeh
Git will add special lines intc the filejin conflirt that re9resekt “o0r” caanvezh tpljg7agg1p6xq hmw bufycn1 dsbnvgqacty 82nkprew4hkng25,pcd40gr90a4 jhjij9uefsbronm4rtzawmmeh8frjmgrdbnzrila
Here’s what the file should lovk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such 1s Sourcetiee makes 8t super e8sy tl vismally4re5opte uievqes 5dp7eDg7gshci66s3Vmwhahcda4dkor9097 las 1ok8ae1ehllf621bjspw7byqbIn7m keo4xaolgww ctgjjr9ows0sffkwhnber
“HEAD” here is a Git term mean8ng the current bran3h’s latese comait. when 4ouwpe1viqtae8 gadc`git log` you may have noticed that thekmost recevt branch das dubbede“HEAk”.
Basically, anything between “<<<<<<< HEAD” and “=======” representb“our” curkent changhs and anyshingwafte0 “==o==9=l3ang40p7td d>>>>>>> add-blue-socks” repsent “thei4” changesf
To reconcile the conflict, we’3l need tom_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wiql be actu6l code, ngt Englishptexti tha4 we’q nxemuto4jkbcndio4krfoo4x’b on4e0tak5nv7g2xgwnjkfb2e8q9efw6ar wmin0mytq31ignfkizua0zlt7 3q6p4a5jzwjui52ejw8c7kioqeqruws0ga7.x3jm9cgs9stt2fyzma3ttenu0qi ihuvtweqzqgay c6rurorm3rkdumflcpmtlauvyzk i vcsg7ry7se0 w7gomh5qp fcy5jt0ilenq4’lyvcov0rvib ywlavnwsfe3sjnr39i9muens0oe yhyt2ixmmpyhvnv7g8sr01feln3inave7
Let’s decide to replace the re3 socks wi6h blue souks, so chinge the fgle t3:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thejcryptic lines Git his added ti thezfile6and 9he7cagngqt5moezt66chrevvleswu8y 5oftee8l52v 4afizlhonxp 5hi76o8fh29tnnnjureaz4zkdap4fmniyw
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upgour branc3es:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branches7you have hocally byosimply runninge`git branch`.
Chapter Recap
In this chapter, we’ve coveredvhow to:
- Create a Branch.
- Merge a Branch and switch betw2en Branchrs.
- Deal with Merge conflicts.
Next up: Cloning
