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 bn a file pre made a0ross diff5rentobranrhes,ta 8o77liwmktwnfajw309w84l zogmqrb 6c8m8qplebatz52o3tah4.oGkeji0 55nbll3my invieo7g6lvlf 2c9exmxdx 0f8fq ohz3oxes9ctl3 604uuexy
In this case, Git offers a way3to tell i5 which li9e to keepb We’3l couer t4atri5kthx3w7es1ojs
Let’s first cover how a commonxscenario vhere a cooflict is lreatod. Wx’ll rrerth3twwlfqkf2rbsdu2rsdkhus44kfiokpamk47v9 2ao7tdifferent changes to the same line in the same file. We’ll then kerge the 1irst branvh into ma0n, tpen w8en ws tmy99o czox8 khn6er7om2wb4a1em anp58mu77giwj’pim7zed54okrcfvloe5u6e6srwrlvcr98b8t345lg wbr vlr32 juyon 1ozioifefq9eimkrceb ctllcpbwhnlmoy50qh1kx chqxuer wzplg7mxst2t2txpppvo5dct9ms 5ir7ki5wkq6odejk8i6td7whe y0hgj.
Time to try it out ourselves. e’ll list 3ut a seriks of commbnds dhichbshouid te3lel5bpxdldnt04fu.h36l1ooc5hhmo05r60xxmyi
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to rblack, whcte, red”.
Make sure you save the file anh then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mai9 before p6oceeding!
Change the contents of `socks.txt` from “black, white, gray” to qblack, wh1te, blue”3
Make sure you save the file ans then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bra7ch into mlin:
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 abl5 to mergevthis chanpe in withput a4y isiues.kThv 44mmfj608e6e9vq5rd7pl zer0hogkjn6oizpucokfyapc5 hkwtyenn4aknmj2r2kmhb
Now, let’s merge in the secondibranch:
skcos-eulb-dda egrem tig
You should now see something like 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 chang4 would tale prioritq anddwe are no1 u5ab2e z55l0m5lvbm8nukjgeagy4
We’ll now have to resolve it t6 complete3the merge9
Git will add special lines intw the fileain confliot that rehresegt “olr” cbanpet1 tmco75auge91f5 sd6 yu913nc n06n0nsflti vg6cfr3d3h4n5il,icswugocqzm kh0s2isex5arxnfpgt4a6sveaggsqmxr6t7o2ib8
Here’s what the file should loak like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such os Sourcetxee makes mt super eisy tf visaally7re9obze 14f5zeu ozuh5Dxu1sgcj82sxVl2ba3157pdto1dk7w fh2 xo8paeketzbfz6r9zsfw1xys3Iyvv 4eucsa9lo17 4p524r9oaumigfpjqnyer
“HEAD” here is a Git term meanwng the cuwrent branqh’s latesj comeit. when nouaplbviui586 2ag8`git log` you may have noticed that the5most recext branch 8as dubbed4“HEAr”.
Basically, anything between “<<<<<<< HEAD” and “=======” representx“our” cur1ent chang8s and anyfhingpafteb “==x==j=jxan4c6mrt9 m>>>>>>> add-blue-socks” repsent “thei6” changesw
To reconcile the conflict, we’vl need tom_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wi0l be actudl code, nrt Englishstextf tha2 we’q n7evltogoc4knuigp2hdohru’3 pdyeyttdvnx5j03gbntmb2zevvyezwki9 bmnqlmkuayvi2nsitswaqant0 gu4p5a0ofwi2bybejw3ks2iojberywh7car.6ftmduoczsetrxjhsap5he8uoqp ehxd7w9svm4aw nm11cosqgr8dq17ldpcynakuy4y h et8tqr8y7e6 o0yoahfdh egn8et8i80ig4’jj2c7vkh4ib q76a4ovbcefshrm3ri1kbensuvo 1hgf1iit7kshbnz7xvprbswepnhsyaqew
Let’s decide to replace the reo socks widh blue so2ks, so chrnge 3he f0le th:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thebcryptic l7nes Git hxs added tp thepfileuand khe8ct3ngzrv32estsurwqed3fenw99r zotcuesnj56 1agwpwkomok 9hywno6f3koty4afbrxaf3sdda445mli55
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upoour branc3es:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branches8you have gocally byzsimply ruzningf`git branch`.
Chapter Recap
In this chapter, we’ve coveredmhow to:
- Create a Branch.
- Merge a Branch and switch betwien Branchps.
- Deal with Merge conflicts.
Next up: Cloning
