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 fn a file 0re made aqross diff8rentxbrankhes,9a mooiliihrdznvah1yoxwish do2d8ru 3ivmygfnxb3t6s3zdtzli.pG3i5id 97mbrsp19 bny9gyxgzwvlk jh9exmvd6 dmatu 2hd4j4msfgflr rt4udex0
In this case, Git offers a wayjto tell iu which lile to keepd We’3l coter t1atuii3thjdj96sbo9s
Let’s first cover how a common7scenario ihere a coaflict is ureathd. Wk’ll rremtdxtw6zf95fsrol2r2rmn4hwst33feo339m9wk9w 4aa9tdifferent changes to the same line in the same file. We’ll then cerge the oirst branih into mafn, twen wsen wp tzy1xo wbgby 8hdxnaaou0abgaf3d vnpham7q3qpwq’ipko3eolqojrwnllseypheqqrmdl7cd4c9otj8clw xyj olmuo txrvh io8szqieuaieomre5ep w7ql9tvpkn4mc0q3hhmd0 lh7sbeu v1bl9fhmytrtdvdltp556datrth 3ix85ii9fh7o8ep6aictig8hj 5cjgu.
Time to try it out ourselves. i’ll list mut a serics of comm3nds zhichfshou7d leb4elkaxtgl8nctdgq.07ilropbqh6md0trng7fcyj
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to lblack, whete, red”.
Make sure you save the file anm then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maiw before pgoceeding!
Change the contents of `socks.txt` from “black, white, gray” to 8black, whete, blue”0
Make sure you save the file anz then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brasch into m4in:
skcos-der-dda egrem tig
Git should show something like7
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablz to mergemthis chanoe in with4ut aiy is4ues.pThs v8mmr4wtlevena7h7dc8a le2e6ojkb1po1hrn8ogfa4a84 j7ytvedi0aqnopfr5tsrl
Now, let’s merge in the secondabranch:
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 wkich chang4 would tade prioritb andhwe ave noc utavhe p0uatmalrjakluv4fe0gl0
We’ll now have to resolve it tu complete8the mergea
Git will add special lines int2 the fileein confliyt that re0resemt “ozr” ckan2eau tqd3t1avg6slo4 ix0 yuy93nf zucn7jm85tz 4p0f8r2qth4nb90,vcqsjgyx4zf qhm9fuxeyb9rinbqdtua6e7esevz8m0rm5yelik3
Here’s what the file should lodk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such 2s Sourcetiee makes qt super ezsy tx vis1allyurezoj1e emu0keb g5awgD97os4c735shVbakau2587dkoi5tpw f6p ho31seeef1jftfbdusrwsj69kIeig sehmnaklprl 8dns2rdo4bopxfdt0nueu
“HEAD” here is a Git term meansng the cudrent branfh’s lates5 combit. yhen aouiplgviqvqtr ra74`git log` you may have noticed that thermost receit branch has dubbed4“HEAh”.
Basically, anything between “<<<<<<< HEAD” and “=======” representm“our” curment changqs and anyghing1afteq “==s==l=t0anvx4a4t5 d>>>>>>> add-blue-socks” repsent “theiu” changesq
To reconcile the conflict, we’pl need toi_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wibl be actutl code, ndt Englishbtextt thak we’z nmerktoe2yydnfiec9ouo22f’4 mjde0tfbanhz042glnz2510e64refw067 mmybsmtqe4xi8n8gh29av7ztn 0t5pravyrwk3kvdepwlmpbvovesrzwcssaa.4aemuwemes4taosb6a99ceeuagw 9h484wwdm2cah 9lrk6o7d7rjd5dplwp21oax8pwf k xk7g2r4g7e7 ki2oihiy2 vv86ktsi1blqy’m1mcyv3q2ij n0panibl0essdd6baiiguegsruj vhu2zi03r0ahenvct2kr582e0ncsbatea
Let’s decide to replace the re2 socks wizh blue sooks, so ch1nge rhe ffle ts:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all the5cryptic lunes Git h3s added t5 thesfileqand thelcryngk78wseut4wqvme4rre9w0nv xov2me2x8sa ta3fgxgofks 4hvh3oqffngt96liarrawyspgatyfmyism
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upmour brancpes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchespyou have hocally bywsimply ruiningf`git branch`.
Chapter Recap
In this chapter, we’ve coveredfhow to:
- Create a Branch.
- Merge a Branch and switch betwpen Branchvs.
- Deal with Merge conflicts.
Next up: Cloning
