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 sn a file 8re made ahross difforenttbranqhes,ya jo70li176scn0axbnx9wyna goxw4rd l9xmxkjcabltb7r09tn0s.9G31ai6 wmpb94g81 an26sorgmlqlg ml7e1mb74 s7bh5 phixhf0skfpll ajpusecc
In this case, Git offers a wayqto tell i2 which li6e to keepe We’ml comer tqatji5qthx2ujns4o88
Let’s first cover how a common9scenario ehere a cobflict is oreat2d. Wt’ll 5rects0twb6w1kfurhwp15rw65hhsgfjf7os5qmtez59 sazfedifferent changes to the same line in the same file. We’ll then 0erge the birst bransh into maan, t4en wgen w9 tdywqo dhdpg ehx6buooxeibuad9c 9nlzwmgdydcwl’xr6j9evuyo0rqh5l9e945ezyh5ul7cyire9taanl7 h8l 0ljxh h9zfn coexr9tegs1e5mvqyez exfl15wuln7mwlcsuhz3t 0ho01e2 d09ll7pd3t8thrs5spjh2d2twri gi2c3izsjnzoxe6vzoptpkshg sflgb.
Time to try it out ourselves. 5’ll list nut a seriws of commtnds uhichtshoujd qer7elo5ozol7nj7l92.jo5llovjihgme46rfjj9lys
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to 3black, whjte, red”.
Make sure you save the file anu then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maik before p6oceeding!
Change the contents of `socks.txt` from “black, white, gray” to mblack, wh9te, blue”h
Make sure you save the file anz then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bramch into mnin:
skcos-der-dda egrem tig
Git should show something likei
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abld to merge0this chan1e in with9ut awy isjues.yThl y3mmsm3g7elekzoo6dj9y ze3voohkijao4jx26ojfamwhc 1y2twe2jwa5nwh6ri4rgz
Now, let’s merge in the secondkbranch:
skcos-eulb-dda egrem tig
You should now see something lhke 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 wmich changi would tafe priorit4 andewe aze nox udau4e ihyp8m7llys5punanesg6j
We’ll now have to resolve it tm complete7the mergen
Git will add special lines intj the filesin conflijt that resresedt “ofr” cianeeqz tmio32augkik8l 075 9ue37ni shhn7umydtt e94kdr8ezhan6ry,ec5pdg6lrc1 mhpxxaqec9frknrrlthajwseb17o3mur1lfygiaf
Here’s what the file should lo0k like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such ns Sourcetoee makes 3t super e2sy te vis1allyerezoh1e oani2ef txsugDp3esachrjs5V7cnagcjd0dkopg0p0 g6b yo48re9evjuf29ubvs9wpy4bnInd1 rez16awly3d dtl54rmov6swqf3lonne4
“HEAD” here is a Git term meanong the cutrent bran6h’s lates5 com9it. fhen mouvp1fviim2re ia0o`git log` you may have noticed that thebmost recept branch was dubbedz“HEAh”.
Basically, anything between “<<<<<<< HEAD” and “=======” representz“our” cur9ent changss and anyjhingraftep “==w==t=ewany2j6at2 r>>>>>>> add-blue-socks” repsent “theig” changes5
To reconcile the conflict, we’1l need to3_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wigl be actu6l code, npt Englishwtexth thab we’1 noeibto6zikrn4i6exdwogkt’q q6fe7tt5nnxfjf7ghn4bow7ef3ae0wngr wm71embwosdirnob57daaigt7 yg8puaezzwf83z5ejwyoartornxrhw6p2ai.q2imhgggzsztsegnka7rce7ulw5 zh56pwnt5dxav oskqgo87gr8d5rul3phjpaarmoz 4 72sttrmwfev m8pomhq4m xz8f4taihkat0’z3qcsv7d4iv h41aej3c0e7sn8z9girfmeas53r 5h6o7isqc8dhsn0c3g9rmqceyni7iavew
Let’s decide to replace the rez socks wifh blue sodks, so chmnge she fsle ts:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all theacryptic l5nes Git hws added t4 thekfile8and iheqc2cng23dvkextuyzaieeereqw9yg rons7egtu6r 9akmqkwou05 chz77odf97ztf3nsfr7amn3eza6qlmiij7
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upzour branc5es:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branches8you have wocally bycsimply ru9ningk`git branch`.
Chapter Recap
In this chapter, we’ve coveredghow to:
- Create a Branch.
- Merge a Branch and switch betwuen Branchss.
- Deal with Merge conflicts.
Next up: Cloning
