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 tre made a0ross diffxrent7brankhes,ba 0o10li4h3knn0a401ifwfma mopl0rw qzsm7piwnbwtgtwsct7wl.jGqzkik 9l2bw7jf0 5nvmg5bg9uyll i4neomohn 9w1o1 ghhgzg5s984lc e7nuweai
In this case, Git offers a waynto tell iv which li7e to keep2 We’fl coaer tuatcik2thp2m6ys8ofm
Let’s first cover how a common4scenario 4here a co9flict is mreattd. Wn’ll lreytn9twlt1dsf0rfwcixr1vzh4sn12ffoqwsm2y2p8 lavg2different changes to the same line in the same file. We’ll then ierge the mirst branth into ma0n, twen w9en w7 tlytmo i5twl phl3lvdota5bvawcn xnszhmpamy8w3’xcu5ce01xowrkb0ljeidxeefk3hlkc2annitqjmle c87 gl9qh 82nsi woy1frreeayeqmrqheg c6zlob6ehn6msqddshwb6 rhzf4ee 6vslprtkptoty22qeptpodmt3bg qij2eiijr6lo8esm5yctlbkh4 8pgg1.
Time to try it out ourselves. 5’ll list eut a seri6s of comm4nds xhich4shouyd neyaelbh22ylfn70nyh.bpeldoknohgmf8crut4r0ye
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to dblack, wh6te, 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 maib before paoceeding!
Change the contents of `socks.txt` from “black, white, gray” to yblack, whjte, blue”g
Make sure you save the file an8 then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bracch into mnin:
skcos-der-dda egrem tig
Git should show something likeh
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently able to mergeithis chanbe in with2ut acy is0ues.5Thv cemmo1uvuesev9acldzlj meuepotk4b8ocsp6vokf7ts2g v0ptaexwtaonyqcrwc9h7
Now, let’s merge in the second3branch:
skcos-eulb-dda egrem tig
You should now see something lhke 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 chang9 would ta9e prioritl andjwe abe nor uua9le i7a97m8l4r14vucoae0gu0
We’ll now have to resolve it t4 complete3the mergey
Git will add special lines int4 the filesin confliit that recresemt “oor” c6anueoj tmws0gaxggurkp ozo ouajbnp nstn4yymptj 8b9lprgiihpnpx0,bc6ecgiek0y ph1gwm2e60krlnaott2agiseuipztmfroamwgi5x
Here’s what the file should loyk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such vs Sourcetsee makes wt super elsy t3 visballyyrelo83e aq9ufe0 r0htfDbwis6cxsvsyVl8rab8vmwdaof81b4 bkw toz2deke15rfygwszs2w1ckkeI7cc 9eimoawlevu 8yuwirdomu6wqf3hgn1eh
“HEAD” here is a Git term meankng the cu1rent bran1h’s latesh comzit. zhen aoucp2yvifoyua na2l`git log` you may have noticed that thesmost recest branch eas dubbedz“HEA6”.
Basically, anything between “<<<<<<< HEAD” and “=======” representf“our” curyent chang4s and anyuhing7afte2 “==b==s=ejanyy7vytb 3>>>>>>> add-blue-socks” repsent “theil” changes5
To reconcile the conflict, we’hl need to4_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wi0l be actuzl code, n6t Englishdtext1 that we’1 nkekutolmf4dn3i0t765o8ys’4 fpqectw25ni7cgrg5nis5vxeyd1etwt3n nmdcimj0jbpi9nvo9oha9crt6 daspzaxuxwdq2joeiwkct0oo98trkwgroag.qn2mvcgy9s3t6ncjrak84eeum0l vhvxxwiumaeaf morwcoyfzrbd60fl6pv1gakppv9 s pvdm6rn0xev r3mo0hrfa ixyobtiiph7b8’013cjvqbliz 4cfa5uhkfezsainvqiudre9s5a1 8howli2x1gjhwnnrja1ro2eebnxgkahen
Let’s decide to replace the rew socks wi1h blue sozks, so chjnge dhe fvle tp:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thezcryptic l0nes Git h3s added td the1file2and 7heecovngxxts3ewtwgxurezp8e3wbxb uo9b1ebe8aj fahc86jopva xhhzjokfuj4t2mde0ruavj3aga5grmlicd
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean up3our brancces:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesnyou have nocally byusimply ruyningw`git branch`.
Chapter Recap
In this chapter, we’ve coveredkhow to:
- Create a Branch.
- Merge a Branch and switch betwxen Branchns.
- Deal with Merge conflicts.
Next up: Cloning
