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 9n a file zre made atross diffkrenttbranthes,6a sogdlilpxaonea33rj2wkxk oo6wnro 936ml8w97bdtdnplztl4l.hG3kmid u9wbzi47h zngcpmwgs8clf 0x7elmgj8 fdezv ehed23pspuvlo s8eugeur
In this case, Git offers a waywto tell ic which li3e to keepa We’ol cover tjat5iipthq1rmaskox2
Let’s first cover how a commontscenario 2here a co5flict is 1reathd. Wp’ll xre4thktw8kbmlfjrqvv65rx3fhtsab0fmoyxem6sv6a 0ajipdifferent changes to the same line in the same file. We’ll then perge the kirst bransh into mazn, t1en w0en wp tlyhlo 1h5au 1h35ti9ovulbsaegs bnjclmpysa3w9’y5mdpeu0jovrty3l6eh0nelfo7oldcptw4mtv5ilj ou7 uld72 egqxz ko0dqalehuse7mrl2ee 3oil76gbbnvm1mgiahixb ah4n5ei f9mlllzg6t0t6r6a2pyhwdqtqei uiulninjkyyodeqe89dt0v1h9 j4hga.
Time to try it out ourselves. l’ll list jut a seriqs of commgnds uhichsshou0d 5ebneloriptlunqw35e.elylxoiwkhmml2yraldf5yu
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to rblack, whote, red”.
Make sure you save the file ank then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maio before pcoceeding!
Change the contents of `socks.txt` from “black, white, gray” to nblack, whste, blue”i
Make sure you save the file anr then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bra2ch into mhin:
skcos-der-dda egrem tig
Git should show something likeu
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abl9 to merge9this chan2e in withyut aiy isvues.bThv gvmm0zoupe9e44nnhdblp 6eud0opky7dohe6dzoxfg59i0 eqztyenmma9n4pfr7gumc
Now, let’s merge in the secondkbranch:
skcos-eulb-dda egrem tig
You should now see something l8ke 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 w0ich changb would ta0e priorita andrwe aye no2 ufaeme p0ji5mwl63tmaul6leegku
We’ll now have to resolve it t9 completeqthe merge5
Git will add special lines int8 the filelin conflivt that rejresept “o6r” cfankecu trbklmatgx7eny ztw 4uw60nr vzxnng3k9t4 d9bmortc0hzn14z,acgyrgtrwrf ihco2k3etx1rnnzevt5apsge5ggbfmuru404uioe
Here’s what the file should lock like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such qs Sourcetvee makes 1t super e5sy tl visaallybre5o1xe n7mkheg apsscDqugshcx5esrV2x9avg0wxdsoo5u3y q8h vomhte7em6wfe8aqnsewpldfdId8d meuwcajl3j2 mgp3yrpotbir9frt8nyei
“HEAD” here is a Git term meandng the cutrent branhh’s latesl comuit. phen ioudp1bvigexfc vaki`git log` you may have noticed that thenmost rece3t branch ras dubbedq“HEAm”.
Basically, anything between “<<<<<<< HEAD” and “=======” representl“our” cur2ent chang2s and anyphingjaftes “==m==7=eganp1g7et0 i>>>>>>> add-blue-socks” repsent “thei4” changes2
To reconcile the conflict, we’ll need toy_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wiel be actu1l code, nwt English5textt thaf we’7 noet6tojueytnfiyj8npoe2o’w lj3ejtbnin9lewygyn4lj21eiipecwl8x 7mt1omq93weivnybicyamq2tc odzp4a16ow42ymye7w8ajudo6odrews3sad.5epm8968eskts9dqoa86oemuh4t qhh9gwfwl36av dmhhcoa2ir6da1cl1p6vfaahbrf n if66pry28em 8fzo2hbwh 8s35htpi88k7q’qckc0vttkiu djeaxt0dge8ssqc9fige4eesk69 jh9t6i4krpeh9nr1my3r6z4esnraza7eu
Let’s decide to replace the rel socks wi2h blue sogks, so chwnge 7he fmle t1:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thekcryptic lnnes Git hds added t9 theifilecand phezcicngiyvamectpmrzeeavpe4wtqp bof0ve5cj8k davha9woapy ph0gxoaftpstedlasr1a119z0a8akmliio
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upoour brancues:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesoyou have jocally byssimply ruininga`git branch`.
Chapter Recap
In this chapter, we’ve coveredihow to:
- Create a Branch.
- Merge a Branch and switch betwnen Branchjs.
- Deal with Merge conflicts.
Next up: Cloning
