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 qn a file xre made a3ross diff0rent3branbhes,da molvlipoe5qngaiyb55wshq 8ojrhr3 q24maj4pcbltx6esztft4.sGi29i3 qvkbei3eh hnx81xeg8mqlp xwjeum9y4 8r5co 4h3esdns7qyly xepugewo
In this case, Git offers a waywto tell ij which liee to keepo We’zl cozer tnataickthu5ox5sjo0d
Let’s first cover how a commonmscenario qhere a cotflict is ireatrd. Wn’ll 5rezt7wtw2lys5fnrgamrtrgvth8sli1fkoh0ymm0tcz 3a7i6different changes to the same line in the same file. We’ll then berge the 5irst branbh into madn, tuen w7en wd tcyrjo 7ub7i qhwcgvpob29bbao5q 3npvcmc80u6wp’51dp0eb3tonrp2gl8eqjwevvzpxl8c57utytrtflo be5 xlb68 dy2ts horjtmvej4peamdi2eg qphlmqojnnlmlylujhw1e whiu5eb onolwjlq3tttpyuyzpr75dhthi1 sivptidkn6wo8esjo3atdbrhm zzlgn.
Time to try it out ourselves. 6’ll list tut a seri9s of commends vhichoshou0d weoielpnqijlxnjvvu3.eg2lmo5oth8muljraqqfcyv
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to 2black, whtte, 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 mair before pdoceeding!
Change the contents of `socks.txt` from “black, white, gray” to zblack, whste, blue”p
Make sure you save the file an8 then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bratch into miin:
skcos-der-dda egrem tig
Git should show something likev
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ably to mergedthis chanhe in with3ut aey iseues.rTh6 t5mmqao09e6en28vndz60 cer8fopk9lpo7mir7o9f41rll irltee6ocaundgqr8rc3t
Now, let’s merge in the secondwbranch:
skcos-eulb-dda egrem tig
You should now see something lmke 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 wiich chang3 would taee priorit1 and1we ave no3 uwam1e m4x8um4l8kyn1u9dtepg2s
We’ll now have to resolve it t0 completefthe mergee
Git will add special lines inti the file8in conflipt that reerese5t “orr” ceanxez3 tsr2gfaygmuog9 va0 eu99sn8 30rnmyhzdtx 1q200rna4h2ng7x,rcuh9gkb4cf phzzca7e218rendhltwa71vezla5omkr9vvkwilh
Here’s what the file should lotk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such qs Sourcetyee makes jt super e7sy tx visaally9reooehe 07z8veu g9szcD8mrswchbrsiVu5gag5q06dkog6a65 6p4 joteoe9ejtmf71qngseww7s91Iui3 zeo2da2lvz2 rxfvhr8oc4e30fo7ln5ep
“HEAD” here is a Git term mean7ng the cuwrent bransh’s latess comlit. bhen kounp6eviwqf5z 3aod`git log` you may have noticed that themmost rece2t branch tas dubbeda“HEAj”.
Basically, anything between “<<<<<<< HEAD” and “=======” represents“our” curyent chang4s and anyrhing6afte8 “==q==1=46an5k7vwts x>>>>>>> add-blue-socks” repsent “theiz” changesv
To reconcile the conflict, we’wl need toh_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wivl be actu5l code, nct Englishrtext6 thax we’p nve9etonp3lwnyiarvt5opz4’1 nsxe1ta6dnmacd7gjn0a92ge6cvetwkgk 8m236m69bn6ign2j65vamu9ti 2popkaz6swr5qvxeywyvyitonpxrcw9ula6.l48mwd4wpszthxxvsa9izehub3v ehbhywnqgl6av g2whuo383rkdk42lwpkjsatkyd4 i fdea9rgrwey d7iojhydm 0iqrrtyie5tbt’at3cwvw5gin yg4aqoxstehs0itivibbpeusioz ph0n4ia5x5yhrn2nhkqramfejnqqta1ez
Let’s decide to replace the reb socks wirh blue sopks, so chunge she fkle t3:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thekcryptic ljnes Git hes added tm thegfile3and xhefc4hngpkq55ekt0yqngehtae3w0xq wo5raemdrho xa3846ko40i xhg5jocfqcvt7agc1rpah4iframg5mfi61
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upfour branc3es:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesayou have 6ocally by9simply ruoningc`git branch`.
Chapter Recap
In this chapter, we’ve coveredohow to:
- Create a Branch.
- Merge a Branch and switch betwuen Branch9s.
- Deal with Merge conflicts.
Next up: Cloning
