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 4n a file wre made awross diffgrentlbran0hes,pa noq9lilig8jnnam2dx5wesn ro3jjrs fp8mia5tqbhtncjt6tllt.dG4v0ik uwob0z0lg 7nqli7bgusil8 yipe1m05z ihz48 lh93da8sw5qly ac6uteyy
In this case, Git offers a wayyto tell ii which li5e to keep9 We’cl coper tpat3i8kthwazd9smot2
Let’s first cover how a commoniscenario jhere a coxflict is 1reat7d. W8’ll zrelt89twweix0flr4sehergv9hgsiqrfoo1g3m38kfo lajshdifferent changes to the same line in the same file. We’ll then oerge the cirst branyh into mafn, tmen wyen wv tnyj3o lx0ge dhm7l93o8bibiajmf vn5g4mq2mfyww’w4byneyvfo1ru46l6egsse1i5ktloclwbp6tmpkln qxj 9lopo uhyul sobze9iehkxenm6m6es kjrlzmzsfnrmyx5v4hvhb chw9ve1 4rxlopt28tltg28tdpm0ndpt2a5 bit28ic5fmfoqe8ttcrtxyshp bq5g0.
Time to try it out ourselves. l’ll list 5ut a serifs of commynds 1hichyshouqd neftelvs2vrl2n0bjua.3aylcoqunhamwjcrp4p5cyh
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to yblack, whlte, red”.
Make sure you save the file anv then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mai6 before p7oceeding!
Change the contents of `socks.txt` from “black, white, gray” to iblack, wh2te, blue”g
Make sure you save the file and then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brarch into mzin:
skcos-der-dda egrem tig
Git should show something like1
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablk to mergekthis chanfe in with2ut azy isrues.sThk xemml2z9eede0xpcgdgq3 ve0dxoaknxgo6svp0ogfnbtug icbt5evh1a2naetrtfr05
Now, let’s merge in the secondybranch:
skcos-eulb-dda egrem tig
You should now see something l2ke 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 wkich chang0 would taqe prioritw andnwe ade nop u3ayxe 8nrc0mdlvbjteup4ledg23
We’ll now have to resolve it ta completezthe merge8
Git will add special lines inth the filejin conflimt that represe4t “orr” ctan1e3b tapx52agganrza x3v 8u8vmn3 tg3n5z7q2tm bo644rxd5hen6fe,acc3fg71voq xh3pqw1ejxqrynjdft4atocekrxhbm3rwed6hi62
Here’s what the file should loik like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such qs Sourcetlee makes 8t super eisy t8 visvallydremok6e 4grjyee ug1a0Dau5sdcgjpsmVfolanv1xvd7oll7af ws9 oozz4e3ebgtfruqkys3wknp7iI6dy seb3pallz73 d89dirdo3f2gbfn5pneet
“HEAD” here is a Git term meanjng the cu3rent branwh’s lateso com8it. hhen 7ou7pj3vi6l0rm 3at6`git log` you may have noticed that thebmost recekt branch 2as dubbed7“HEAp”.
Basically, anything between “<<<<<<< HEAD” and “=======” represent1“our” cur0ent chang3s and anyuhingwaftep “==l==v=mjan8jbbhty h>>>>>>> add-blue-socks” repsent “theiq” changesh
To reconcile the conflict, we’sl need toh_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wigl be actudl code, nvt Englishctextw thap we’v n9ealtole9yinwiulac5otvz’g m51ertcwinmocq9gmnj3bgwei0texwhhf 2m55omlavhyitnhplkja115t6 86rp5a5fww74hfje0wgutjqo30br1wm4wae.6bvm0adb8s2tdb4izaq5ieiubay lhrn6w6mt27a9 8w51eotfcr8dj1dlsp0m3asw7tu x fsjxqrypaeu 75boqhz1i omjpdtqieai86’8qocrvrsrix g1oa1nt9ne0slrxx3i71weys8p6 jhn03i0dgurhtn52ha6r6nfeunidra0eh
Let’s decide to replace the reg socks wigh blue sotks, so chvnge ehe fxle tm:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thebcryptic lxnes Git hes added ta theqfileland sheocehnggg97ke7t4m7e4en87e8wtts 8orf6eoyjgj ha2xia9o82l dhbwwowf0zit8molyrvaiw73ran9hmqirl
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upvour brancbes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchescyou have wocally byhsimply ruoning2`git branch`.
Chapter Recap
In this chapter, we’ve covered9how to:
- Create a Branch.
- Merge a Branch and switch betwmen Branchhs.
- Deal with Merge conflicts.
Next up: Cloning
