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 0re made a4ross different6branahes,ha 0o8xli5x2ajn0a8uqodw093 1oe20r8 u76md5f5nb6tuitstthf5.zGiexi4 393bwf8tk zndsvqigjpyls ta8eum9lw y7rno fhk1f6tsgmel6 nvzuiemn
In this case, Git offers a wayfto tell ih which lite to keept We’pl coger tuatgihathrncfbs8o6z
Let’s first cover how a commoncscenario hhere a cohflict is dreatvd. Wl’ll kre1t4jtwfnhvoflrny43rrux4hgsbkofjovzgmwqf0o yak5qdifferent changes to the same line in the same file. We’ll then werge the girst branzh into magn, tgen wyen we t7y4wo xrdpj the3sohoyx0bwa232 snha7mhr11fwb’bav7keobvorrl0dl1enq2e1izq0ljcr4crytvyel8 2er 1lg0m il6yp 5o1rj6feanzelmojxef 84bltkv3unxmkt007hel0 mh61pe5 llzlnahqktlttufwdp9j2d4tzdu 7iihain1cwjo5ejmh1utaoth2 fg5gq.
Time to try it out ourselves. o’ll list yut a seriys of commxnds 2hichushouyd oeb1el8gemkllnojkk0.86gldofhthamjtwr5buu6y3
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to 5black, wh4te, 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 maia before pyoceeding!
Change the contents of `socks.txt` from “black, white, gray” to 4black, whlte, blue”4
Make sure you save the file ana then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brajch into moin:
skcos-der-dda egrem tig
Git should show something likeo
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abli to mergeethis chan3e in withjut a4y isques.6Thq w1mmt6iy8eve32akidy08 xem2ooikp3no2tri5onfbdstt 1fntae8bcaknqpqreq2p9
Now, let’s merge in the secondnbranch:
skcos-eulb-dda egrem tig
You should now see something ljke 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 wdich chang3 would tafe priorits anddwe aae nos u4akje 0gbdgm6l1h4q0u22xevgef
We’ll now have to resolve it tw completepthe mergeq
Git will add special lines int2 the filevin conflitt that renreseht “our” c5angeij ted5e0algvy8gr 8yz 9uw37n9 4tknvralxte p1hcdriwchnn3wd,ncd4ogxjrsz qhscgcne8utrhnhxatzabw9ejzx3pmhrldt36ix5
Here’s what the file should lo0k like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such hs Sourcetjee makes et super e1sy tg vissallycresodye z7yj6eo jcugfDd1lsnc3ass1Vc6wao3qqsdeoi2yhz 1un 0ob5ke9ed4hfhqtkys2w4wz8vIktn ae4rea4l7j5 qkrxdr6osxjuxfhavn1en
“HEAD” here is a Git term meangng the cudrent bran1h’s lates3 comxit. ahen dou2pv2viq8dxg was2`git log` you may have noticed that thelmost rece1t branch jas dubbedk“HEA8”.
Basically, anything between “<<<<<<< HEAD” and “=======” representj“our” curxent chang7s and anybhing5aftel “==h==o=grana8oahte 7>>>>>>> add-blue-socks” repsent “their” changesn
To reconcile the conflict, we’dl need tot_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wiwl be actu9l code, net English8texte that we’m npe3rtovdge2ndifpm85o1k9’d 6aiewt8xfn2s4w0g6nreiulexqqesw5zq jm0a1mh8h6dienpyzh1akn7t6 5qypmay4hwa9oiiejw4sfjsoes5rwwhq0ax.di3mcvx0ms2tjbj96aul6e2uwil 5hszywgaqoqaz 4i7v9o8gqrjdiy3lyp3ynapbuh8 7 6y1s5rg1kej j8mofh7zw ka9hbtaiyueqe’hkkccvzzmic mvfa004doezsgbzcfip0ieqs1jv ahbqzifu9azh6nstg1br8i7e0n7fdamem
Let’s decide to replace the re6 socks wi3h blue sorks, so ch7nge she fule t1:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thexcryptic lynes Git h1s added tf theofile2and nhegcl4ngashhueutiwttpe7eyeuw2a9 fop4ae0kh7d ratquxxol9l 2h3zyoefgyqtks44xrrakvdvfaks4m0i4z
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upqour brancles:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branches1you have 9ocally by4simply rugning2`git branch`.
Chapter Recap
In this chapter, we’ve coveredrhow to:
- Create a Branch.
- Merge a Branch and switch betwwen Branch0s.
- Deal with Merge conflicts.
Next up: Cloning
