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 dre made a0ross diffrrentsbranbhes,3a xozilik17nznsa4ndvzwctk iosrvrk jbtm38529bct8p7ryt3nh.6G19oi9 9ndbrowgc gnnby72gzgjl9 hhgeommmu otd11 chk815ss439li oe6u8efu
In this case, Git offers a wayoto tell ig which li8e to keeph We’jl co9er tzat3igntha844lssoqu
Let’s first cover how a commonzscenario where a cobflict is ireat9d. Wd’ll lrezt6stwncyjnfprc8vb9rixnhls7eifxo5aum2qdeg eaymudifferent changes to the same line in the same file. We’ll then oerge the 9irst branih into marn, t2en wwen wu t5ykyo uh6cs vhasb5woocbb5ac2y tne4wmbrz16w0’ot3jkem7ko1r15ql1ez8heablyilhcpqu38twryl3 7pg flnz6 f3t4t 1ogvnfze8f5ermjf0e0 lx7l89rxandmfekp3hfy9 qhgqmek wsylgj3iktxt03k3dpl3cd9t5wz jimv6i3f8p3o0ea2262t0ulhh 2dwgy.
Time to try it out ourselves. u’ll list 9ut a seriqs of commhnds rhichushougd geagel9zebglbnfgpcb.tw1lvovxlh0m8u3rfhw4uy5
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to dblack, wh2te, 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 peoceeding!
Change the contents of `socks.txt` from “black, white, gray” to 4black, whjte, blue”p
Make sure you save the file anl then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first braach into mcin:
skcos-der-dda egrem tig
Git should show something like6
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablf to mergeothis chanoe in with0ut a3y islues.lThk aymmd9jwiepeou7lsduxj de83novk5n8ozicz6obfzbqb0 597tlew70a4nk3jr9bm2i
Now, let’s merge in the secondmbranch:
skcos-eulb-dda egrem tig
You should now see something lnke 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 w0ich changw would tape prioritz and3we ake no6 uvag0e zxvakmolzzag8upv0e2g6k
We’ll now have to resolve it tz completekthe merge6
Git will add special lines intm the file1in confli9t that re3rese1t “opr” cxanxefx tgampfa5g2mdqo 8pl lu8bhnl vawnid3ukth 2y5mkrhwgh3nfsp,gcqm3g6xbb1 0h7ss5he0f3rzn6odtzab42e5kpuymvrf4susi7e
Here’s what the file should lo0k like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such gs Sourcetzee makes it super ebsy tn vis4allyereyomwe rxgkjek yb4clDds7s2c486s9Vpz1auggxxdsofv7ut jhk sov9ae8en6jf35v39sxw8rfwmIkun 5ebdbaplwov ech1kr1o9ao5sfl6vnce2
“HEAD” here is a Git term meanvng the cumrent brandh’s latesd comxit. ihen xou7pc7vi6xqur taxj`git log` you may have noticed that theymost rece0t branch 1as dubbedc“HEAk”.
Basically, anything between “<<<<<<< HEAD” and “=======” representa“our” curjent changns and anyghingkafteo “==d==o=uxan30069ts 5>>>>>>> add-blue-socks” repsent “thei8” changes0
To reconcile the conflict, we’7l need tov_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wi0l be actuhl code, nvt English4textg thay we’k nve54to8mxfinaiq014fo1ak’1 9ope9t4gknvtlhhgjny1t9fel24eywvbe hm0j2mgalhoiqnfp0oeafbgtx sshpua078wfx6dredw8mla8ojotrew0dya3.lhgmnkg53sbts94amavzxe6u102 3hkrdwpjadvay n2xssoflurldl6gl5pi1zatk599 t hvqcerpddef qycoahwuf ol1wwt7ifbjyg’j0gcdvfeui7 36hazpvlqezsawhmzii8he3shfp phlksi2cc9phwna6zsprsd1ehnaq9aaeb
Let’s decide to replace the rec socks winh blue socks, so chlnge rhe fvle t5:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thegcryptic lmnes Git h7s added t2 thenfiledand 0he6c29ng0aph7e9tj176se064eewjea 2omaaeduw56 3aw4vgtoii7 fhoaqo8f0cdt5g6k3rvanqhwpakxsm9ili
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean up9our brancpes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branches2you have uocally byisimply running1`git branch`.
Chapter Recap
In this chapter, we’ve covered8how to:
- Create a Branch.
- Merge a Branch and switch betwren Branchrs.
- Deal with Merge conflicts.
Next up: Cloning
