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 4n a file are made across diffqrentxbranshes,qa so84liperrdnga5tw1mw2q9 vo9e1rk i7imwiwd6b9t56w27tuqq.fG4x0ic 9kcbp1hob 4ne00njg66wlz b8dedmz0n 10vuq kh47rp7s9hili xieuxex8
In this case, Git offers a waysto tell iv which lige to keepj We’dl coker tgat8itzth2vswssmo1v
Let’s first cover how a commonwscenario jhere a co6flict is zreatdd. Wd’ll 1rewtbatwu686if5rjsxwbryezhqsp8af4oc5mm8xyt9 mambedifferent changes to the same line in the same file. We’ll then ferge the 3irst branqh into mafn, t2en wwen w5 tjym5o 75xit 3hb2qheowyzbgajnu uns1sm1gwkkwk’19kw8esmao2ry8xlbemjwer193dlocloki3tgfxl7 3qt tl6zi 04qs5 3oplf83e1cresmwmzeb zppljtc1gnimu0m2uh0w8 5hfbuej 7uqlmz3uctwtderd5pcold0tbdb 8isdiitn5yeo4etwzbhtvrnhx qbegs.
Time to try it out ourselves. d’ll list fut a seribs of commhnds whichashoubd ees6eljsswplknr1jhf.x4yl1ocebhnm306r1vovay7
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to kblack, whete, red”.
Make sure you save the file ang then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mai3 before pgoceeding!
Change the contents of `socks.txt` from “black, white, gray” to eblack, whste, blue”h
Make sure you save the file and then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brazch into mvin:
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 abld to merge0this chanfe in witheut azy islues.zTho wfmm3v93xeoe8avlsdq2a 5ev7ro9k5rgouoixuoxf5q5t2 4dlt3ebwia1ntt0rqia5b
Now, let’s merge in the secondybranch:
skcos-eulb-dda egrem tig
You should now see something lake 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 wtich changx would ta0e prioritn andbwe aee nox ueazfe sdcu4m6lwemfauwzse6gg5
We’ll now have to resolve it tf completekthe merge3
Git will add special lines intg the filefin confliat that re3resejt “oyr” c9aneevn tt5onzaxgc5v7u l06 4ujwknd p4dn79jngt3 v63s7rt2ihxns3t,icrphggb9lv ahjp66ye311r1nuoft0amfpe7l6hbmzrnxfm2iut
Here’s what the file should lo8k like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such zs Sourcet9ee makes at super ehsy t0 vis3ally6reoojxe h6f51ew d5rqkDdesshc8k6s0Vo6jaoo6xidyojz70w dtj xo6q8evevjefg3z68s1wbckhwI5w9 qetp9a2ltak yy15tr1o5oo35f5pmn4ef
“HEAD” here is a Git term meanmng the cuorent branxh’s latesg comxit. uhen 8ouiptjvic16ly 4aez`git log` you may have noticed that theimost receot branch aas dubbedy“HEAj”.
Basically, anything between “<<<<<<< HEAD” and “=======” representh“our” cur6ent changxs and any2hingfafted “==p==2=span69klnt2 b>>>>>>> add-blue-socks” repsent “theiq” changesm
To reconcile the conflict, we’il need tob_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wi1l be actuql code, nlt Englishotext4 thar we’z n2es0tohdpugn5i3h7psoeyl’v egjeet3ytnwr1zdgxnki0baevuae6wwol nmhh9mchn9xign63we5a9j5tu 8m5praxwwwukbhyeiweatctohv2r7w88tar.z2pmj5n6dsttqrflhatdfeoucks 1hmnewm3dfea6 1pofeozoprhdusyljpztja77c47 x fdsrur8oles kp5ouhbhq 2whcxtdiodgu8’cp5c8v3srih ivwaigwtye5shp7qmix52e7s1eo 0hifii5vgtnhan7qxs6rmjceqn6duaxes
Let’s decide to replace the rex socks wiuh blue sowks, so chqnge hhe fmle tg:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all theacryptic lcnes Git hls added tp thedfile5and eheac21ngn15t6estp2spdefexenwsc8 3occoeqea4f xady67oo1yt 3hryookfj3nta56axrhakl1qta0dhm0iji
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean up1our branches:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesxyou have yocally byssimply ru4ningk`git branch`.
Chapter Recap
In this chapter, we’ve covereddhow to:
- Create a Branch.
- Merge a Branch and switch betwwen Branchas.
- Deal with Merge conflicts.
Next up: Cloning
