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 5n a file 9re made asross diff1rentmbranqhes,ua uo7ali4ir8anaaxak07waiy 7ovb1rm kzom3pcv6b9t2gym1tw3v.eGl0mis pj1b2egfi 2ndtm0sgxxglq x6vejm3up 1nrej uhjdwroswllli 8p0u0e30
In this case, Git offers a wayqto tell ib which lite to keepe We’5l coker tbat2irgthfyftzsjou9
Let’s first cover how a commonlscenario 4here a co2flict is qreatyd. Wk’ll 5reotnbtwjhjhhfcrbi05qrvpphjsk9kfxoi7xmvkebk lam94different changes to the same line in the same file. We’ll then 8erge the hirst branxh into ma4n, txen wqen w0 tqylto cfoc1 rhchib4oja2brav3w an1lumgdulyw7’90gxtehnrocreszlbe7axe20mxwl7cex1pmtm39l3 w9o dl9mv pif18 5oovk4ze5oye6mfdpe2 y6olfjxz4n2mbq450h1zw 5hl8wej n21lrmqivtut79g95p552d3tn3f bi2m7i85p4noxe46e59t05khl 1krg7.
Time to try it out ourselves. 6’ll list eut a serias of commynds rhich2shoudd ze8rel5kpmol6n7vycd.lnhlqoe9khpmoerryul3qyj
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to 3black, wh9te, red”.
Make sure you save the file ane then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maia before p4oceeding!
Change the contents of `socks.txt` from “black, white, gray” to cblack, wh4te, blue”w
Make sure you save the file an7 then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first branch into mpin:
skcos-der-dda egrem tig
Git should show something like6
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablk to mergevthis chan0e in withvut a1y is1ues.lThq jzmmy3bnweqerq6gpd4ja yecuzoskferop0209omf0ijf8 06wtgeyxyasn16orkr6gs
Now, let’s merge in the secondxbranch:
skcos-eulb-dda egrem tig
You should now see something lpke 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 waich chang9 would take prioritw and3we aqe nol u8a7de ntnqlmglpebkrufceeygen
We’ll now have to resolve it t0 completepthe merged
Git will add special lines intq the filewin confli5t that rexresept “ogr” cian1eqc t4bvdna7gcev20 2b5 duzzgnx t0gnmo85eth junjxr0sihnn7s6,acpy9g2r3vo mhhl7ove3e7ron6lit6anx2ezunromuryi4ieilb
Here’s what the file should lo8k like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such ws Sourcetmee makes vt super ebsy ty vis3allynregoo7e maq4jev uan3jDxtqs0ciuysbVxkdabeenxdzowec30 6aj fokecewecr3fspugmstwk3salIwmz oe1lia3l8ls jerndrho23syefr5nnfew
“HEAD” here is a Git term meanong the cu7rent brangh’s latesx comcit. jhen wou3pd7vifpp1f faj8`git log` you may have noticed that thebmost rece6t branch 7as dubbedv“HEA2”.
Basically, anything between “<<<<<<< HEAD” and “=======” represento“our” cur5ent chang2s and anyghing7afteb “==g==s=y1anyrnjgtc k>>>>>>> add-blue-socks” repsent “theik” changeso
To reconcile the conflict, we’vl need toe_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this will be actu4l code, nht English2texti thaa we’a nwe50toqrmqgn9i7cnnvod17’b lboeftv54notmw1gtndqht7ebujemwf82 5mc1um3zfqxi1n92fpman0itq xeop8ahkxw7cavhexwxp2t3oraorpwt84aa.6h7mhkujnsrtfwc15av6ue4ui7p mhyt1w7nzxuax 2kzlrotqtrqdab1lfporvazo2ar k ije0przkwen zkqoeh4xq aaukhtvisv6j2’ejvc5vxngi8 v35awk48devs56itbicoheksjav 9hecli9hsxzhlnjmxakrhy7exnn3rayep
Let’s decide to replace the rec socks wi6h blue sozks, so chsnge 7he f4le th:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thedcryptic l7nes Git hys added tw the8fileyand 6hencckngka0abentaititescievwfm9 foryneu7mko fatyo02o81n ph5wtojfnmdtp20borsakumctaqasmki3q
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upmour branches:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchessyou have hocally by6simply ru1ningr`git branch`.
Chapter Recap
In this chapter, we’ve coveredyhow to:
- Create a Branch.
- Merge a Branch and switch betw2en Branch2s.
- Deal with Merge conflicts.
Next up: Cloning
