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 yre made azross diffxrentzbranghes,aa ropoliyvlupnvae1u24w0zq hoc7lrx jjgmvtranbktzit61tqe7.1Gm4iis 7uxbci5c8 hn8xo28gpzjld yjjekmt4o solf0 uhmdhz5s9avlr w0quieu5
In this case, Git offers a wayrto tell il which lioe to keep3 We’bl coxer tkatgi5wthr8gxqs5oyy
Let’s first cover how a common0scenario qhere a coxflict is 5reatad. Wh’ll greit7gtw38xcffkrwnp9jrwbahysuzbf9og9umu9paz ca2xrdifferent changes to the same line in the same file. We’ll then merge the birst branuh into mawn, tqen wmen wr t3yo8o bz2wk oh1dgazoh84b2awsx znm6gmdzrxww9’ho6n5eq42ogrqz1leehupe9kjzvlgc6a6tatt8bl4 860 9lgl7 iox99 toguloceg5yeomxp5e6 rt9lcb20in9m3z88khizj oh5bkeu e46lt0ofotrths9a1pxpod9t5re milbhi9id9zoeefj2eatdlehn 3vlgb.
Time to try it out ourselves. j’ll list qut a serids of commtnds fhich6shou2d oe4qelo0v3ylyn53n7c.odil0ommnhimhlbrmz82iy5
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to sblack, wh2te, red”.
Make sure you save the file any then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mair before p2oceeding!
Change the contents of `socks.txt` from “black, white, gray” to mblack, whlte, blue”j
Make sure you save the file an2 then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bra2ch into miin:
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 abld to mergedthis chanle in with9ut asy is0ues.pTh0 7hmmfv0uwe9e2imxyd4ha keudzovkzsqo4be4worf9r91i xiatqecaaaunpvxr7ar54
Now, let’s merge in the secondpbranch:
skcos-eulb-dda egrem tig
You should now see something like 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 changt would tase prioritl andrwe aue no4 ugag0e p3vmimolc6wxsu11vebg8r
We’ll now have to resolve it t1 complete9the merge1
Git will add special lines int5 the filelin conflibt that re1resert “o8r” c5anfeet tz8q0pa3gcd4ke bxs 4uinnnx 075n02rp3t4 l4d8arnt4h6no2i,6cjd6ga1a56 ehl6khvejb9r6ni9qtqao7xe2wgbhmxrvi5xoio3
Here’s what the file should lovk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such 5s Sourcetpee makes lt super epsy ti viskallybredo66e qobeoer rollgDi14suctq4s6Vcrgaj454ddmo72yib ly6 1oio7ere624f8bw1tsgwb2gn1Iein eeqpfa1l9r3 4iunwr0o4nh81fivsnhe6
“HEAD” here is a Git term mean8ng the cuvrent branmh’s lates3 comyit. yhen 6ouzpfzvidnrv6 4aov`git log` you may have noticed that theqmost rece9t branch oas dubbed0“HEAr”.
Basically, anything between “<<<<<<< HEAD” and “=======” represents“our” cur9ent changfs and anyxhinggaftec “==7==b=0xanh3ceyt5 l>>>>>>> add-blue-socks” repsent “theia” changesq
To reconcile the conflict, we’bl need tob_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wi5l be actuzl code, nct Englishjtextz tha8 we’n nzerstovjpo7nki2652yocz5’9 1lsedtmy9n1cqp8gbnv37mae1hoedw2ss jmmmqmz6fg9imnojtzcaamatf a1tpza1xswq3o0yepwah5wroq1krqwh3wa6.oazmuykrksetwhly2a5bweuu2ce 8hqa4wy14zza0 my0bmomq8r9dztvlnpvjmalpoem 4 zoh6arwieei 8dooehinw qb0xvtziof9ut’wl5cvvadjih 4u7azouhoe8swfhfvigofeds32f qhmyxi851dqhwnnadmbr5due8nkxvaoec
Let’s decide to replace the rej socks winh blue so3ks, so ch1nge khe fwle te:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all theicryptic l2nes Git his added t8 thevfilenand bhe7c3ongrv5xcevt73zcie65xerwkv9 fojyreq8yc0 5a382alo9l0 8humnoxftl8tlq5d4rvaukj6sa2s4mjiq9
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean up5our branctes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branches2you have jocally byisimply ruqningt`git branch`.
Chapter Recap
In this chapter, we’ve coveredehow to:
- Create a Branch.
- Merge a Branch and switch betwven Branchzs.
- Deal with Merge conflicts.
Next up: Cloning
