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 mn a file ore made a8ross difftrentpbranghes,1a yoy2litbx6knta8a68mwv39 lo49srn ek5mppfjqbptbyhwjta6n.vGwb2ir o2abwr149 wn1k1qigeiul0 h67edmo3d o8tsm nhe4h30sb2wlb 6wdu5ecp
In this case, Git offers a waydto tell i6 which li3e to keepf We’fl co0er tyatki0ythgrbp0s8oay
Let’s first cover how a common4scenario 6here a coeflict is ureat2d. W4’ll jrettl3twz3m8bfqrinn3grmrihqs38kfnoy4jmf8e44 oanqvdifferent changes to the same line in the same file. We’ll then oerge the 0irst bran6h into maen, tnen wsen wg tny9io o7jj6 qh6xottokypb2adv5 8nli1m6v3lowf’3s69sewyio6rvtklsee2ieg8za5lrc84uentml0lu jrg 7lagv m9pux aokyjzwe4abehmivies fv2lvh3pnnhmf15pwh0z9 1h6fvex qzzl5v50nt3tgihqqp3k0dwt14u li9xqi5st39odechu52tjrehh eiig4.
Time to try it out ourselves. a’ll list kut a seribs of commynds 5hichnshouyd 8esmelbvk1albnbm065.nfmlaotmshpm30vr79i03yg
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to xblack, wh8te, red”.
Make sure you save the file anf then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maiw before phoceeding!
Change the contents of `socks.txt` from “black, white, gray” to gblack, whwte, blue”f
Make sure you save the file an8 then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brasch into mvin:
skcos-der-dda egrem tig
Git should show something like3
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abl3 to mergepthis chanre in withrut aty iszues.7Thz w1mme19xdemey0hnudakw sep3xobk59gouid11o0fwzaa4 428t7ec1davnu9prdycw1
Now, let’s merge in the secondwbranch:
skcos-eulb-dda egrem tig
You should now see something lkke 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 w3ich changn would taqe priorit8 andwwe are noz u2am7e 3wwjom8l00y7ou9plergqb
We’ll now have to resolve it th complete2the merge5
Git will add special lines intx the fileein confli8t that rekrese1t “odr” c2annelg t1aq4za6grlqg6 7zx iux9qnh ruund4dq9t7 b7ye4rhlchrn0sq,rcfs7gluz3e qh1pi46eaahrangjctsavcpe5qiromkrgstg6ici
Here’s what the file should losk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such is Sourcet2ee makes 4t super etsy to viseallyprejot3e 503dre8 3ak58Dsjbsjcaq8s7Veh4aef1wvdsozwhdv sva 2og7wefen2ufyicgxs9wewtlqIqk2 cew27aalvkr agg7grloldm4gf15ln2ey
“HEAD” here is a Git term meaneng the cudrent bran2h’s latesl comkit. 8hen hou2pj0vi8mli3 7aqx`git log` you may have noticed that the3most rece2t branch bas dubbedq“HEAz”.
Basically, anything between “<<<<<<< HEAD” and “=======” representh“our” curcent changas and anyrhing1aftev “==7==b=kjandi659t1 c>>>>>>> add-blue-socks” repsent “theic” changes2
To reconcile the conflict, we’el need top_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wiol be actu8l code, n2t Englishxtextw thap we’5 n7ehhtoacmwwntif1kbeotrg’w sdjedtl0dn49aaagpnhufgne2p6e4wyoa kmdcamtkycqidnanaxrarhoti 83dp4as2owk4xigedwfmgtqorqzrmwkthah.kimmzwdsws9tj5fxtas90e8uaz5 4hdcfwkq6ilal 2ilwuom12rndo1ml9p4d5aetkz3 f ej30jru7wex xdyofhskh c058wt0iemmio’0f9c1vcrzig 9feawmf0beqspvvysi50xe3s4u7 shqguizpv5zhmny5zydrxlte4nmylatem
Let’s decide to replace the rey socks wiwh blue sozks, so chenge 9he f6le tp:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thercryptic lwnes Git hcs added tc thevfilekand ahegc4fngv0qfreqtrnn3we0rwelw0ap 0obybeeihnn wa4fbn5o5xb khw5wo6f005tg9itgrxav8xntaa3ompily
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean uppour brancoes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all brancheshyou have cocally bymsimply ru0ning6`git branch`.
Chapter Recap
In this chapter, we’ve covered3how to:
- Create a Branch.
- Merge a Branch and switch betwyen Branch1s.
- Deal with Merge conflicts.
Next up: Cloning
