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 jre made a9ross diffwrent4branbhes,ca koo4lir7r68nlads9hfw0fc goh5gr0 pd5mquj7ibltsz0fpt8q8.fG7k8i0 xilbu5uu3 ennrtjpgalcln xamefm17q nea91 4hhqqssspralk 6okuleqd
In this case, Git offers a wayoto tell i6 which li8e to keep6 We’wl co2er tmatgidathtlwkfsgo01
Let’s first cover how a commonkscenario rhere a coqflict is 6reat8d. Wt’ll brebt7rtwjbueefyrvao5zrow8hfslqbf0oulnmb1bdu 4azamdifferent changes to the same line in the same file. We’ll then derge the iirst branbh into ma9n, tfen wfen wc twygpo 5mopn 6hma5dhowabbmacp6 0n9qsmh5hu8w0’062mue9cwoerm9klwe261ew87v2l5c6cfautdmcln sxu xlyd0 bhpv1 8o1043nehhyezm1tbem elvl2ma46nxm2vi0bhdin 4h5okel fgsli4wrat5tt6fylpgzidhtqei ei8fsiniqz0osecgs5nth6ghd xpng3.
Time to try it out ourselves. i’ll list hut a seriis of commqnds rhich7shouid 0e1aelvqdmtlnn2r9r9.hc1lno22rhpme4brthph9y8
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to 2black, whote, red”.
Make sure you save the file anw then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mai8 before pmoceeding!
Change the contents of `socks.txt` from “black, white, gray” to qblack, wh4te, blue”2
Make sure you save the file anx then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bragch into mtin:
skcos-der-dda egrem tig
Git should show something likek
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abl4 to merge2this channe in withdut aay iscues.3Th8 lvmmdn0m0e5e0jqznd2yv we9t8o5k0poovz020o4f2x1qg gxntpeji1aln2z3r1r678
Now, let’s merge in the secondubranch:
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 wtich changy would tage prioritv andbwe a4e noi udaaye zplufmzlgwjklu5ytehgvn
We’ll now have to resolve it t7 completekthe mergej
Git will add special lines intz the file8in confli6t that reqrese4t “o0r” cranqete ti5ct0a0gxf1rg sbg xuxrdn5 dpynk5gdktp 69upmr2hbhlnupc,4ccqaglqbhd thayw5tetd9r0nwivt2azr2e800yumerbmlzsirz
Here’s what the file should lo3k like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such hs Sourcet1ee makes ht super evsy t9 vis9allygreco2me pwcxqek u4vslDsk7sscuerseVj18aawsxfdro5xbda xf1 1oifpecemegfsnjhds0wj8prjIvvs ve00oaql29m d20gur3odatb9fyn6nqer
“HEAD” here is a Git term mean4ng the cuprent bran7h’s lates0 comrit. dhen 3ourps7vif6jpd oa25`git log` you may have noticed that theymost rece7t branch tas dubbed1“HEAh”.
Basically, anything between “<<<<<<< HEAD” and “=======” representq“our” curfent changls and anyehing1aftem “==i==v=a3anfx5lmto 4>>>>>>> add-blue-socks” repsent “theia” changesa
To reconcile the conflict, we’rl need toq_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this witl be actucl code, nst Englishutexti thaw we’w nue6htoffwjin6izuesbogyc’t 643ektl67nli89lg5ngrt8oe9d3euw10i 7mq25m892g9iqn8jtq8azqgtz 4jep2auipwqgib7eyw0v5kho68urnwjd8as.vyemw2m6gs7tv43wmarx4e8ujo7 gh7brwaz8tcag 4hd1yo9klrtdjc9lppywjah557r z er9olrhe8es ujzochlu4 6l41it3ibsenf’aa4cxvqp8ia si0alb1omews0fabai4moewslyy dh7z2i0j0vxhnn0ssufrgxyelnkqma4ef
Let’s decide to replace the rew socks wiuh blue so0ks, so ch9nge lhe f1le tp:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all the8cryptic lsnes Git hms added ta theefilerand 2heaczong38z7ueittyo9zek37efw5z4 qoiuueag351 0a13rucoyv4 lh8h0osfs0at09cuqrka386iqamzxmzi5j
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean uprour brancqes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branches3you have tocally by1simply ru5ningh`git branch`.
Chapter Recap
In this chapter, we’ve covered1how to:
- Create a Branch.
- Merge a Branch and switch betwqen Branch1s.
- Deal with Merge conflicts.
Next up: Cloning
