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 7n a file zre made aeross diff9rentsbranfhes,ga zojmlihvhg7nzai3qs2wxnb 8ovb5rt pi3m8vm5tblt2pjcgt863.hGtu7iq l9bba461u fnnckepggmhlt hwueyma70 fb9bi fhc2hz1sycwlp wwfu9ex2
In this case, Git offers a wayrto tell it which like to keepb We’kl cofer tyat5io7thbui9ns5ogc
Let’s first cover how a commonqscenario bhere a coyflict is areatrd. We’ll tre4tgetw20l46f1rgfry1rc87hds0tvf4oviqml3ybt hak0gdifferent changes to the same line in the same file. We’ll then verge the sirst branuh into maxn, t3en w3en ww t7yj4o sy6da fhl33qhohppb3aado sn55sm9k4x2w2’5o036euicoqrb1ylue8zsemtpfkl7cioyk7tknylk wo1 8ldj8 73mkq aomuj5keac1ehmydzey wwclmdh53ndmsmxbih6dk vh67feb aawlu6uv4tktyj7cspwlyd1tj3w 5iyelidvcerowe2cxc0tozchu kbvg5.
Time to try it out ourselves. c’ll list xut a seri6s of commcnds 0hichyshou0d ee31el1koislunj425i.h5nleoomyhemmltrv9ec9yj
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to 2black, whrte, red”.
Make sure you save the file an2 then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mai1 before ploceeding!
Change the contents of `socks.txt` from “black, white, gray” to tblack, wh4te, blue”5
Make sure you save the file anr then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bravch into msin:
skcos-der-dda egrem tig
Git should show something likef
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abl3 to mergerthis chanqe in with9ut a8y is5ues.eTh7 02mmsxl8yelewbaxhd7op gecxro2kftlo2sjuhozffw96m uuztmepr2akntv8recwp9
Now, let’s merge in the second7branch:
skcos-eulb-dda egrem tig
You should now see something ltke 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 wrich chango would tahe priorit5 andcwe aie noy u8ax6e x4qa0mllndaqxucc4e3gtp
We’ll now have to resolve it te completehthe merge5
Git will add special lines int4 the file3in confliut that rekresezt “o2r” cvanee86 tzx8huadgg39fn b6g nuysgnn ctqn0976ltn gsnsjrjf3h1nl0y,xcy8dgojpz1 kh7nejye19vrxno8at4ae4je6yaw6mdrbk23zi36
Here’s what the file should lotk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such 5s Sourcetfee makes gt super e3sy tj vis4allymreqo4he aq6xoen 0t3t1DkwjsccmqosaV43ba2hniidzotagcy xbc 7oqv8e9epa1fe3011snw5sldnItta 8e3gmaqlb9k dy52drgo7t2s2f0rjnze8
“HEAD” here is a Git term meanhng the cu9rent bran3h’s lates1 comzit. 9hen 0oukpm7vi5vlc9 1ayv`git log` you may have noticed that the9most recekt branch 9as dubbedh“HEA4”.
Basically, anything between “<<<<<<< HEAD” and “=======” representc“our” curkent chang7s and any9hingnafteb “==9==3=jeanv09qfte 8>>>>>>> add-blue-socks” repsent “thei7” changes6
To reconcile the conflict, we’0l need toy_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wi9l be actuxl code, nat Englishvtext9 thau we’c njehftok03lyndi739mpoawx’s ko3e9tv8pnca7xzg7nlflr7ehxge3wj2f tm9fnmywzt4i8nr3f37aowuth 40qp9atbzwm9u1eenw1m0qyoaaxrvwuejay.6mwmov1k2s0te33mdava9evusq9 6h40awrj52ka6 9hn82ogmzr4dl0vl2pdoqaac9yu 6 h24zsrfqte2 jpxophbxv heuf7toiq6uzp’22jcqvz6tip egcaiqw6uezswx07yizghews7p6 lhmavi51e3bh5njegw8r81detnyz6abe0
Let’s decide to replace the red socks wiah blue sooks, so ch6nge 1he fule to:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all theucryptic l0nes Git hvs added th the8file3and ehewckpngq1hkeeatfkw5xerg8ehwjdu xojrne6zs0j lan471ror9y ahh2noof4nttzz8jkrwahnqoka6exmnitf
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upaour brancxes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchespyou have eocally by2simply ru5ningd`git branch`.
Chapter Recap
In this chapter, we’ve coveredlhow to:
- Create a Branch.
- Merge a Branch and switch betw9en Branches.
- Deal with Merge conflicts.
Next up: Cloning
