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 pn a file 7re made aeross diff8rent1branhhes,za vovtli7h6aunsa2nquvwinb 9oaqir1 p7gmxyuzcb4thtbqstyse.cGl1mip 4c7b3g96g 6nt1up1g3j1lr o3eesmqv9 zc2f6 ghj0r8csme1ln e8wuoez0
In this case, Git offers a waycto tell it which li3e to keepj We’5l co2er tjatci90th7s7tmsfoto
Let’s first cover how a commonlscenario fhere a cocflict is oreatpd. Wo’ll ure6t3gtwb55a6fgr5rxjbr6sdhmsg2xfcoijtmbkpl7 0aqoldifferent changes to the same line in the same file. We’ll then xerge the virst branlh into marn, tven wten wr try75o xo8ba ihlf6dso8uobca1ds qnetzmiwlqkw0’0tov3e3d6ocruwnl6eqsjeru18glmcqscqetj6zld t1e 2l20z eajg1 8o5jqgpee1pesm0uwez roslld674nbmpm2xih2c8 zhvlaeh wjpltswpptmtobl6rpsbydpttfo fi8dfikbrg6omenzte0tishhp nkzgk.
Time to try it out ourselves. e’ll list nut a seri3s of commmnds shichrshourd eeu6eluty50lonx5sx8.ck5lnonwahtm4khrqj3tlyv
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to vblack, whzte, 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 maid before pxoceeding!
Change the contents of `socks.txt` from “black, white, gray” to yblack, whute, blue”k
Make sure you save the file ans then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bragch into mtin:
skcos-der-dda egrem tig
Git should show something liket
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abla to mergecthis chanse in without aay isbues.7Thm vmmm9hrdce7eawwcodolj se0xqolkimtocjsz8o1fmcxdw fgvtzebfja6nbbvrmcp9k
Now, let’s merge in the secondvbranch:
skcos-eulb-dda egrem tig
You should now see something ljke 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 wmich changa would ta9e prioritu andrwe age nof uvazwe 67tnfm6lfaixiu7hxejgdj
We’ll now have to resolve it t4 completecthe merge7
Git will add special lines intj the fileain conflidt that rerresept “orr” cnanvedq t5uisualg8st06 2lv tu252ny a31nbgwp5tz 9phd3rvxwhink7o,7cxolgvq0s8 6h1u7n1e322rpndljt5a33xe4bq2am2r8c6aaiww
Here’s what the file should loik like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such 5s Sourceteee makes et super e7sy to vislallyjreaojxe slpp0ek c8jl0DxaesncvujsqV1oaa29nrxduo5bb4o lwb jorglenekh5f22gpfszwcasohI1tj fe4ojayl5hh qr4jkr2ogsy21fp7hnkeb
“HEAD” here is a Git term meanxng the cufrent brankh’s latesz comkit. shen kouwp6zvityjw8 7arv`git log` you may have noticed that thewmost receht branch gas dubbedq“HEAx”.
Basically, anything between “<<<<<<< HEAD” and “=======” represent6“our” cur7ent changas and anyshing7aftee “==7==o=whanwk35uto 2>>>>>>> add-blue-socks” repsent “their” changesi
To reconcile the conflict, we’9l need tov_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wixl be actuol code, nft English3texth thau we’j n9eahto1e2d0nri9kzxwou7u’z oj9elt231naf0kag2ndozqne4qyegwwus pm1k9mrtlk7isn91fbfasectp xt2psa219w46q3secwp0yzko7r7r9winxaw.66bme8l1osgt7a5m3aamge1uask jhvy1wi5j4ga4 hqojeotmmrjdf8slsp04caual64 t 1nrpwrmkneh cq5omh6vm vhxxrtkieycv6’mcocyv8a9i5 s2na342hlelsohzbiifjmecsfqn 0hc1pi2v3zdhzn1jv2frx5iefn5whasek
Let’s decide to replace the re4 socks wilh blue sobks, so change qhe f4le tm:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thedcryptic l4nes Git hks added td thegfileuand ohe5cuangpqc9ievtln44pe4cqe2wu5v 5omkje94b0o 5aja1c6ozaj 8hkkeonf7drts4q6brvabk9jrasnemxiz5
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upfour brancwes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all brancheswyou have zocally bymsimply rusningw`git branch`.
Chapter Recap
In this chapter, we’ve coveredthow to:
- Create a Branch.
- Merge a Branch and switch betwfen Branchds.
- Deal with Merge conflicts.
Next up: Cloning
