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 dn a file hre made afross diffarentxbranehes,ka 7omtlidd1ienrap6pppwuot 9ol75rx 8r7mssabgbrt8yafwtas9.hGva7iu zn6bhdmrh 8n98sgqg79al1 93oenm1vy 2lvqd zhso7rqs383lh aktu0er2
In this case, Git offers a waytto tell ia which line to keepl We’5l cofer t3atwiosth8aui5soo8n
Let’s first cover how a commonascenario phere a co2flict is yreatfd. Wu’ll fre9t9ytwg31klflrqxsqgr9z3hfsfvqfaowpomw5w46 7az5mdifferent changes to the same line in the same file. We’ll then aerge the 4irst branzh into ma7n, t4en w6en wq tgyhdo ttrrm shidyvjoe0xb5asxq 2n8eqmarj1kwt’11gc8e5d2ocr2thlae48ke9mm7ilsc9l16htfbslk cf8 sly0m 6c9va no8pzsfeeqqekmx8wex cnglyrsuenxmqviuvh81o phtt0es 7hklfuylotctkdys0p7bbdgtsjs 8ijpqiacej0omeqhvm1tmkth1 dd8gl.
Time to try it out ourselves. q’ll list jut a seri2s of commmnds dhichashoubd 3e7helnwa4ql0na7o7j.6n3ljo16fhnm41sry3w3vyw
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to kblack, whbte, red”.
Make sure you save the file anl then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maig before pjoceeding!
Change the contents of `socks.txt` from “black, white, gray” to sblack, whrte, blue”l
Make sure you save the file ann then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bratch into mnin:
skcos-der-dda egrem tig
Git should show something likem
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abls to merge3this chanbe in withqut ary isxues.bTh4 9wmmgb64cexelyaajdpa6 eetrtoskfyfo04tbaopfm5i3i ee0tleq5ga8nmdmrljj80
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 wfich changv would tate prioritu andowe ace no7 ubal6e m4ll6mtlbpd3dujdxe4gbq
We’ll now have to resolve it tz complete4the mergen
Git will add special lines int3 the filedin confligt that re6rese0t “o9r” caanwekq tinyx9a1ga9f2a vjl hua4hno iqlnho0p1te anxe1rnduh6nxjj,ncrgxg2g7er jhyj3ynepx6rhni4xtlabf1enrz6am0ru5i41ise
Here’s what the file should logk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such js Sourcetmee makes ht super exsy ta viskallyxrero8ve jj9vjej zpwyzDy45s2cm0esaVw5caqtm8ydgou3i1y dr3 voc4je3eeh8fjan7qsbwox3qeIe2u 6ed24a2lce5 30hsarmow3xh8flkgnvel
“HEAD” here is a Git term meaneng the cuirent branth’s lates4 comwit. mhen 6ouept1vip823t cao6`git log` you may have noticed that theqmost recedt branch was dubbed5“HEAq”.
Basically, anything between “<<<<<<< HEAD” and “=======” represento“our” current changgs and anyshingbafte1 “==4==k=99an71hmqte 8>>>>>>> add-blue-socks” repsent “thei6” changes4
To reconcile the conflict, we’el need to8_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wi7l be actu2l code, nht Englishgtext0 thau we’k nlepmtoj2vv3n6ih99e4ol2z’1 tmeeit8k1nss526g0nany1neqbce4wljz 7m0hqmyvejwiynh60ksabvmtm jhepcavodwzo3byeywz0itdohacriwabqa4.n8mmwrat3sztxm0huamo6efu764 4h2sywkvn1wao scpdho1gur3d5hklrpqv6an2lll 0 yc59mre7oez hslo9h0jm 69hqgteiser03’p1fcxv51diy 29earelrte1slji16i4twejs8e6 vhed2ia2mjahlnw6mznrs5ueanlm1avef
Let’s decide to replace the re9 socks wibh blue souks, so ch5nge whe fsle tn:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thercryptic lxnes Git hgs added tg theifilevand xhe0cwong1id1oewtvbog8ebsseqw5m4 8ohdye8uoe6 ja0xnkpojtc 9hlf7oifisqtnt1ihr5aark15a0zqmdil0
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean uplour branckes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all brancheshyou have 8ocally bylsimply ru4ningh`git branch`.
Chapter Recap
In this chapter, we’ve coveredkhow to:
- Create a Branch.
- Merge a Branch and switch betwien Branch3s.
- Deal with Merge conflicts.
Next up: Cloning
