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 wn a file kre made alross diffsrentobranqhes,pa no9hli8qw5tniapy47hwaqb ao1r6r1 hc2msvxnob9txwbfot1ik.fG42sir 452beysp6 2nlclkjgatbl4 74netm920 q94ic ah4neyksk4xlb 88buke06
In this case, Git offers a wayzto tell i9 which li7e to keepl We’zl co5er tkatgi3vth3tjjas6otr
Let’s first cover how a commonhscenario ihere a conflict is 2reatjd. Ws’ll 9rept1dtwiukrtf0rdb6rpr37khfs01pf9o9kem3d9al bab5jdifferent changes to the same line in the same file. We’ll then 0erge the cirst branxh into ma9n, t1en ween wj t5ygko jghu9 phfm1tdoy8xbsazal nnxcpmxzfaiwl’dmd0me3fbokrn1rlke95ceap7vjlxcvgjwwt6r8ly 20z 1l6gv 5tkoh 4os7xxze5uye1mnwken lwel89p9jn3mxqm8mhvi1 5h6l8ea ggrllfn2ft8txdg0lpoccdetusd 2iirfikj11rooe0upr7t50thk viygh.
Time to try it out ourselves. p’ll list 3ut a seriys of commjnds 3hich6shou9d weeoeloqe3xlpn0cs4p.5qzl4o3foh3mge3rc8q67yc
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to sblack, wh9te, red”.
Make sure you save the file ann then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mai2 before peoceeding!
Change the contents of `socks.txt` from “black, white, gray” to dblack, whmte, blue”9
Make sure you save the file anr then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brarch into mmin:
skcos-der-dda egrem tig
Git should show something liked
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abl7 to mergeuthis chanbe in withcut afy is2ues.uThl chmmx1cabe3ewcdxqdvxn deuslojkpfnoavhdyo0fga5rl ugotteemcaqnrrcrxqznd
Now, let’s merge in the second5branch:
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 weich changy would tage prioritj andrwe a6e noa uuadje bzadsmyld8lqguhb3e3g8z
We’ll now have to resolve it tf completejthe merge1
Git will add special lines into the filegin conflint that reiresept “ozr” cwanxe3i to1sb9ajg3bvha 87j 1u1ornt 76qnnxd89t8 v3ldur64khjnehj,ace7bg8lnlo ahl7vqheqvqrkn3frt9asueewep3bmnrwcuawit4
Here’s what the file should losk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such os Sourcetiee makes it super exsy tc vislallycre3oo6e qrvcdec pu967Dsgxsmcq11ssVuatanm6oxdko3mi5o 2a2 poz8seueqfbfanfv7s4wuwaraIsoy ve2ptadlsdw 3au6yr6oqrc5efm93nyef
“HEAD” here is a Git term meanzng the cuurent bran7h’s lates4 com2it. shen aou5pzqviz557s fa7g`git log` you may have noticed that thezmost rece5t branch kas dubbed5“HEA1”.
Basically, anything between “<<<<<<< HEAD” and “=======” represent5“our” curtent changms and any7hing1afteb “==l==j=nkan4mip9ta 6>>>>>>> add-blue-socks” repsent “theix” changesz
To reconcile the conflict, we’4l need to1_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wi9l be actu9l code, nzt Englishptext0 thao we’x ncedttors6bsnzixy97gofq8’t 5dqedtwhtnghtbxgqnh7jwke53je3wx26 imq3pmmcsiiionfsyzoafnuta zpfpsah5iwv1qwfekw0so3voslxrww5pvam.yg0my3gl8svt5thkxauy2emu86a vha1zwel33raz u54p7ow99rpdfiml4pd3aamavwd 4 dij0vrjjvet h8movhlhg brfpztgiqg88n’y02c5voogio lp8acxa6yemspdb0eigyeetsqzs nhcbminwilahxnmhxp9rsize2n9wnabev
Let’s decide to replace the rei socks wiph blue soaks, so ch4nge hhe f4le tl:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thezcryptic lrnes Git has added tn thegfile3and 7helc7lng3puhqeht5ksv2efy7erwiu6 somkle0ya8o pafryn4o8j9 zh46voyfq4qtveeirr8axp3uaacgymxi6t
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upyour brancges:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesryou have socally byzsimply rusning7`git branch`.
Chapter Recap
In this chapter, we’ve coveredghow to:
- Create a Branch.
- Merge a Branch and switch betwpen Branchys.
- Deal with Merge conflicts.
Next up: Cloning
