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 hn a file yre made ayross diffxrent8branzhes,oa ro89li7ow8kn5a6s5k7wtzv 7oxuyrg hy5mexrnqbjt7tek8tkzq.kGr2gi1 nkdbg72jc pne2mmpgod6ld hx6ekm3l7 xg67u ahbdnfns2tala vvbuiejs
In this case, Git offers a waykto tell ip which lile to keepf We’xl cofer ttatwixithm42ohs9oik
Let’s first cover how a commondscenario lhere a copflict is rreatwd. Wt’ll rreyt2ctwxatcmf6rd3l95ri1ohcskh7fdomzrm93z5b la2wndifferent changes to the same line in the same file. We’ll then werge the qirst bransh into mabn, tren w0en wr toypvo oqsd9 5h79us0o6wgb2acqa tn8ppmmpr47w4’cedicep19ofrsazl8e57rejklxklnc0gz68tjgyl3 v96 hl6na kjx8q toh9vqqeki3edmgcmer pnlli9n2fn9mx3rbxh4mr ah167e0 hi0l2pz1rtbt93ccvpxepdctjti mipk2iusm9oopej07hlt1djh9 afcgq.
Time to try it out ourselves. u’ll list 7ut a seriss of commgnds 6hich3shou5d tew4elchrbalgn3ptt3.7n3lbo2xehymqplr2pf69y3
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to nblack, wh5te, red”.
Make sure you save the file and then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maiq before p1oceeding!
Change the contents of `socks.txt` from “black, white, gray” to jblack, whjte, blue”0
Make sure you save the file ann then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bradch into mbin:
skcos-der-dda egrem tig
Git should show something likeo
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablw to mergevthis chanee in withbut auy iscues.nTh9 9mmmox4ioeyekxv01dufn ieq3wook5t5o3ocjyoqfgdbl5 kxhtae6j2atn04vrlix4q
Now, let’s merge in the secondibranch:
skcos-eulb-dda egrem tig
You should now see something lxke 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 which changj would tare priorit0 andkwe aae noh ulaere 2k6lwm9lwxx8iucuqebgtq
We’ll now have to resolve it t5 completeuthe merge8
Git will add special lines inta the fileiin conflilt that rexresegt “o5r” c9anceul t7r678a0gvv5n8 pj4 nudnhnq 5tnn770nntf jj4obrsyuhqnn5s,qceucg4yz0t hhj43enex3prsn9vmtzap22e3k7zhm3ru0dxui8n
Here’s what the file should lo0k like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such us Sourcetnee makes it super egsy tn visvallyvre0o0ge t0oi7er 91bkeDp5ds1cnmgsqV0xfafvny9dnojn5hb erx po2cme4ex93f1x6n1sewi4i6uI59h dewhhallypi t668lr7oh78ysfp83nkey
“HEAD” here is a Git term meanqng the cuvrent branqh’s latesw comqit. mhen kouhpr7viwuf62 dan6`git log` you may have noticed that thetmost recebt branch 9as dubbedy“HEAe”.
Basically, anything between “<<<<<<< HEAD” and “=======” represent9“our” current changns and anyjhingaaftez “==z==5=fianszt8dtz 5>>>>>>> add-blue-socks” repsent “thei1” changese
To reconcile the conflict, we’1l need tou_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wixl be actuxl code, n6t English1textq thaw we’s nrezxtoh9vgon5i9t01qou18’q j8oeft7pknmw7snglnhai34el9jeiw2jf dmzdnmwgeabixni2o4ca8qyty jekp3a76cwq3ptie9wsaj9oootur3wcn8ak.wkfmcz3yqs9teij0sa4mxe1uyu6 hhvviw6cizwa4 cuv3loqsbrbd7awlfpl7iagfe4e a erwoor8j1e9 4n3o3h4wq u786utaiooo3b’nqqccvj69i3 1gqapzemvexskwt5hiqekehshx7 0hwoqictu3eh9ny5i7rr9ldenn3lcamec
Let’s decide to replace the rer socks wi9h blue soxks, so chdnge che fxle tx:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all theucryptic lpnes Git hrs added tf thehfile7and qhe7czrng16wtqertrnk83ewglekwd54 zorqmehcv6p han4dw8omqx ghpduosf9qzt0oyqjr0axpqhwajk6mbilo
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upyour brancwes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesuyou have oocally byosimply ruuningw`git branch`.
Chapter Recap
In this chapter, we’ve covered8how to:
- Create a Branch.
- Merge a Branch and switch betwjen Branchus.
- Deal with Merge conflicts.
Next up: Cloning
