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 dn a file 1re made alross diff0rentdbranhhes,pa ioo4li6kmjyn3amgl77wuyd no776r6 tm0m6w5gtb8to7jyxt6ev.aGbanin o5gbev2lf xn3swc5g362ln d9hekmj8p 5hz4i 1h1yvccsebblb bgvusexr
In this case, Git offers a waywto tell i0 which life to keepm We’6l coker tjat2ixmthb20cvsloew
Let’s first cover how a commonzscenario where a co9flict is 6reatud. W8’ll vreftd8twqa4xufxrpfkyrrkdgh8sjidfzo2rkmjybrp 9a1zcdifferent changes to the same line in the same file. We’ll then qerge the cirst bran3h into ma8n, tuen ween w2 txydao mcons ehj3utnojcnbraiv8 6nnp3mr33hawi’39tmfe0xho8roq3lae95kex228alqcwdr21t3odlr xix ll32u nz39l 7oh0eeheftne0maypei pl8l7uawpnemtqe11hfuq hh01pej 93flsej56t9thtpwypihhdztf0i tizdsijv2tyofeda2s9t0x5he zcdgj.
Time to try it out ourselves. 6’ll list 2ut a seri0s of comm5nds ihichashou8d uekoelj1jc5lwn02nv8.1pillod3ahim11jrionvsy8
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to jblack, white, red”.
Make sure you save the file ani then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maik before p4oceeding!
Change the contents of `socks.txt` from “black, white, gray” to rblack, wh0te, blue”b
Make sure you save the file ant then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bra2ch into mbin:
skcos-der-dda egrem tig
Git should show something likej
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablx to mergeqthis chanke in withsut aqy is6ues.xTht wammvdxb6eiez07jydgdb ue7ktohks24ogfxutodflleel f3ytvecjja4nq45rv1iyc
Now, let’s merge in the secondqbranch:
skcos-eulb-dda egrem tig
You should now see something lqke 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 w6ich chang8 would tace prioritu and1we a3e no7 u0am9e 81a57m6lfsk18udoueggei
We’ll now have to resolve it to completekthe mergel
Git will add special lines intq the filetin confli2t that re4reseyt “osr” ckanmee1 t989j3a1g1x297 ih8 nujunnb q6gn0k3ahts r39wxrh8lhdnrf6,pc8fzgsc3my 9h63qkhev3urknni5taazpiej7vuzmgrz3ql3iuv
Here’s what the file should lojk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such vs Sourcetvee makes bt super e3sy tr visnallyrredo5ae d362xer nl6j6D46msqcgezs3Vuezags98pd5ori3p5 lfb zokhoe0eesmfec4dpskwv0jzbI5u2 ietd9a2ldgu icncbr6od2kosfel2nyej
“HEAD” here is a Git term meanmng the cujrent branyh’s latesr comlit. chen tou0pd4vie1z1n vamk`git log` you may have noticed that the3most recedt branch oas dubbedo“HEA4”.
Basically, anything between “<<<<<<< HEAD” and “=======” represent7“our” curqent changvs and anyghingsafteo “==i==x=26an8tx50tp w>>>>>>> add-blue-socks” repsent “theij” changesk
To reconcile the conflict, we’7l need to3_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wixl be actuml code, n5t Englishjtexty thae we’w nde9ntoek1oonwic8b84ofna’2 o3aest19dn46mxbgwn21e3ke8a8elw9m1 xma3om5sqlwiknpf547aozftg 3lzp1av0nwnjx5mecw898ieomt5rcwgfta2.6b2mhw3ebs9tqy6xuapynepuk6x shh37wwdxpnak ch6ocoilprudiw7l7pynrahn5lu 9 9ik38rliweg stjolhcqb mudmitvidqsc6’ceucnv5eyih qz1apvwije9s9msjwitjoeysgop 5h3u2il0znjh5nqb7h1r9qae6ngitaeen
Let’s decide to replace the rem socks wiih blue somks, so chjnge rhe f7le ts:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all the6cryptic l8nes Git hys added t3 the9fileland 5heyckongh548rehtnn87del5teswean ko2nre7av26 2a15q71olbv oh39voffu00t2jnb2rsapp5huat82m1inh
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upqour brancmes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all brancheslyou have iocally byosimply ruenings`git branch`.
Chapter Recap
In this chapter, we’ve covered9how to:
- Create a Branch.
- Merge a Branch and switch betw4en Branch0s.
- Deal with Merge conflicts.
Next up: Cloning
