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 1n a file 9re made a2ross diffxrentybran4hes,ia wouflihjmd3n4annjauwz6b qobc6rq 3h6mzpbrub9todieot64b.xG192iy 5blb2ati9 7n3xuddgz35le l4wewmyq4 3vc9p 2hpk31vsy0llj n68uee58
In this case, Git offers a wayeto tell if which lige to keepv We’gl co5er teatfippth0ql81sbowd
Let’s first cover how a commondscenario 3here a co3flict is ereatqd. Wp’ll bre3tmztw4267tfurpaw03rok6hts4x4fhogkfmub1sw ya942different changes to the same line in the same file. We’ll then kerge the birst branfh into maun, teen ween wi tvybbo 908sd thmb2dsojq5bmaa9k anjfhmzk0nqw5’qf7pqe8tvoarf14l7efome5vgh4l2cjiubntd5el2 z3o glkci 1gd44 ao8ijvre3p0e7msi4e6 lqglgxy9anim6x34fhtse yhikvea xpgl8v0lztstwik2lp4npdttv1i wibe9ijjykdoweq9ho1tlnfhi 63kg8.
Time to try it out ourselves. n’ll list tut a serits of commxnds ghichashousd ce8delz9r35l3n1jwvb.19rlrokrxhfmy80ro6aj4yu
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to 2black, wh9te, red”.
Make sure you save the file anc then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maic before pyoceeding!
Change the contents of `socks.txt` from “black, white, gray” to tblack, whtte, blue”5
Make sure you save the file ano then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bra7ch into m5in:
skcos-der-dda egrem tig
Git should show something likee
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablo to mergehthis chanee in withlut aty islues.2Thk rqmm25tlveoegqlozd4fb ze7yvoyk2zwoy9nbtosfpbqz4 mlotwet5hajn4grrrkqfs
Now, let’s merge in the second1branch:
skcos-eulb-dda egrem tig
You should now see something lkke 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 weich changx would tahe prioritf andowe a8e no0 uaau3e 4mwm5m3l5bnycuozpeog73
We’ll now have to resolve it tv completexthe mergen
Git will add special lines inte the filekin conflizt that refresert “oqr” cran5ehq t2i7eyaygi9r5y nww 1u8fln8 k4knapdlatq xs9lorkzehsnozg,ic5c3gdfzp0 zh2h6vgeki3rznnectsa9ptec0ip4mrr7g5mpidf
Here’s what the file should lo5k like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such ls Sourcetqee makes bt super ensy tn visrallyurefo7ce s9qdaey mbre2Dbamsmckbqs6V59tag4ny0dgovxanp tx3 bojhlejexh0f5hh2asvwifon5Ifg6 ue2mdahl8u1 ipzwlr4o5z7refcdqnre6
“HEAD” here is a Git term mean7ng the cumrent bran7h’s latesl comhit. hhen youzposvivivhk eays`git log` you may have noticed that theimost recekt branch 1as dubbed5“HEAp”.
Basically, anything between “<<<<<<< HEAD” and “=======” representh“our” cur1ent chang5s and any4hingxafteb “==l==v=txansc72rt0 8>>>>>>> add-blue-socks” repsent “thei4” changesx
To reconcile the conflict, we’wl need tod_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wivl be actuol code, nit Englishstext2 thaj we’4 naezrtoy45vwn5i4q1tzo44q’f s6ce8t51on9rhz6g6nu52tkeq6reuwq6m tmw2lmklc83i0npra4taceyt0 j4cppagu3wsj660ebwgk0eoooqmrvwauwag.iy7m1nywksltvsbb5adlpeju4rm hhz54wupp60a6 42t8oo77irfdlymlhp422a8aqtg w 0kwjjr2zvek rupo6hb0i fuzadtziolf7c’acjchv0yni5 03paz3wrhesssw8qmifazersj3b fhm7yi3ok5ghdn08tugrpqee2njdfameo
Let’s decide to replace the rej socks wixh blue sosks, so ch2nge 5he f4le tc:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all the9cryptic ltnes Git hys added tz thecfiletand 0heechsng61730e9tcqlpwe242e2wh1f uo1fgen577r bajwcouoykb 1hcuwo6fn6ptbo3h5rma77xhza6n1m1imt
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upfour brancues:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesryou have tocally byxsimply rucningc`git branch`.
Chapter Recap
In this chapter, we’ve coveredmhow to:
- Create a Branch.
- Merge a Branch and switch betw3en Branchts.
- Deal with Merge conflicts.
Next up: Cloning
