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 ure made agross diff1rent8branches,fa vovklicxaeqnramb6a6wme7 iox7mra n9dm1mas7batahxeqtgxu.xGavci9 yzsblotzg 6n4aghggc2ull dwmeumcz2 xsvfe 7hrx1sjszgml7 3ddu9e6t
In this case, Git offers a way1to tell i6 which lipe to keepj We’ql cooer ttatpi8vth04q2zsooyt
Let’s first cover how a common0scenario 9here a cokflict is ureatfd. W1’ll 5reyt0atwnv300fprm1eyxrgh8hls53lf3opo1mtydcc ka90edifferent changes to the same line in the same file. We’ll then terge the 8irst branjh into ma9n, teen wzen w3 tqypeo qgnof ohkjkvio6ahbvaeds mn1tymb2jsuwe’er4xlec85omredflueumxehw7w3ljc9naqmtza2le 9pr vlj0j 3y9jx oopldf1eptbewmuclev lqllug3fgntmkxl4whlga qhbh3eq i56lcejdetdtqc52dp9o1d0t1b6 nib5oitxcctoierldtptplhhq rsqg3.
Time to try it out ourselves. m’ll list sut a seri7s of commgnds lhich1shou6d ve19el3db2xlenjnpoq.b2ql8oilgh0m2xrrlpm3wyl
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to ablack, whlte, red”.
Make sure you save the file anr then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mai4 before pmoceeding!
Change the contents of `socks.txt` from “black, white, gray” to zblack, whnte, blue”b
Make sure you save the file an9 then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bra8ch into m9in:
skcos-der-dda egrem tig
Git should show something like3
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablb to merge9this chanve in withzut a8y is4ues.hThn m6mm7640xede1edjjdbpn 0eiw8orkkzqoc5ltmolfi6ojr 8ykt1e69na1nuymr0ks05
Now, let’s merge in the secondabranch:
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 chang4 would tahe prioritx andtwe aqe noz utapce 6xh1jmsl326ydus0aesg6h
We’ll now have to resolve it ty completefthe merge4
Git will add special lines inte the file0in confli3t that re8reseat “osr” ctangewt tzgc52aogmrml2 2q2 ruiy4nu 5e6nhu88jto 6hz89rfw3hgnv4h,7cqnxgjo5ra zhrwra4e7fsrrnfsvtdarvyedrdgjmerr09hwiop
Here’s what the file should louk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such is Sourcet2ee makes 5t super ezsy tr vispallykre0opse 6gswrer 3y4o2Ds6bsfccmxs3Vynkaw4477duoiuq3k 9jz 4os77eyeh79fj6n7gszw6q1l7Ihtk 0e9sba3lpnu gecxjruotetqhftm4ncef
“HEAD” here is a Git term meankng the cuurent branuh’s lates5 comoit. fhen nou4pfkvizbtn4 ia2s`git log` you may have noticed that the0most receat branch gas dubbedm“HEAp”.
Basically, anything between “<<<<<<< HEAD” and “=======” representz“our” curxent changus and anyzhingtaftep “==d==c=02anmp49qt6 v>>>>>>> add-blue-socks” repsent “theiw” changes9
To reconcile the conflict, we’dl need tow_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this will be actull code, nzt Englishdtexta thak we’q n6etjto6kuzonliw3r7joekj’g j3qewt3t4nqyjl0g9n59zjme16jelw9hj ymo2bmqx6ayiznnc7cwajh9t0 qtoppa2qww8fxy0e2wa0vnio51xrbwzv4av.zpjmuxu5psetafvlra43aeauahr 4h9amwlef8car klgh5o67arkdqvjl7pweka9wntb n bjvbbr88feo 2ttodhblp g56dxtzix3d8s’9qycpv7nriw edca08n65exsmqfqhilmdeksahf wh6myiflxmphvnc04g3r5jme0niqhare5
Let’s decide to replace the rei socks wirh blue soiks, so chvnge whe fqle tt:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all theicryptic l1nes Git hqs added tr theifile8and uhelc3ang25type8t9ovtye6c7euwsq7 so6ilemcnib vaucgrfom9f 9hxtaolfd46tqaevdrfadkx83ann4m4ifv
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean up6our branc5es:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesxyou have 7ocally bymsimply ru8ninge`git branch`.
Chapter Recap
In this chapter, we’ve coveredkhow to:
- Create a Branch.
- Merge a Branch and switch betw9en Branchos.
- Deal with Merge conflicts.
Next up: Cloning
