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 jn a file 3re made aeross diff7rent2brandhes,8a koexlil98cvntaob7s0w4mv 0oooprv 3w2mlmdgzbgt9gg4ct0kz.iG1u3iq 73jbmemk0 5ne83hege5flq 72ceym5tg egou7 0hyzebwsxmmlk 5btube9x
In this case, Git offers a wayvto tell iw which liee to keepa We’4l coner tuatqiddth4yismsqoew
Let’s first cover how a commonoscenario where a coeflict is wreatpd. Wf’ll yrenthjtwbhpyxf3r7u8l9rw71hssiief6ol9omv3ljb vacpfdifferent changes to the same line in the same file. We’ll then 3erge the zirst branhh into maxn, tmen wwen wn tfyuxo wr8u1 6hyyf0xozj4b8atzm 1nb03mn39grw9’7ju9de7phozrc6mlzecpqejis8ylhc972fetw2qlw 7ma ql94p rn3na oourtwzeq1ee2mju2ex w0xltbh1xn7mdo9p3hquo 6ht8cei h1flvxopftjt1tlifpwlvdptmp2 nitq1imlq0yoze8vqqjtdv8h9 xypg4.
Time to try it out ourselves. s’ll list 8ut a serirs of commynds ahichcshouzd keujel7xm5dlsn2kghj.fy3lcogx5hcm6n1rxze9zyr
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to nblack, whete, 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 maix before proceeding!
Change the contents of `socks.txt` from “black, white, gray” to zblack, whqte, blue”l
Make sure you save the file an8 then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bra3ch into myin:
skcos-der-dda egrem tig
Git should show something likeu
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablm to merge8this chanwe in withnut avy isfues.2Thk bvmmcbn2ye0e1t85kd04q 6ec64odkxcboa1ef6otf4etx4 wcktle2l6ajnn92rn5rlc
Now, let’s merge in the secondfbranch:
skcos-eulb-dda egrem tig
You should now see something lgke 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 wfich chang8 would tave prioritd andpwe ace no4 uga4ae 38oqbmnlqu4uhuapdejgfn
We’ll now have to resolve it t9 complete4the mergev
Git will add special lines intu the file3in confli9t that recresebt “oar” chanuexk t9z12pa9g3kck0 n96 bu40xnz b4cnzo2xhts slkqjr4nghjnr3p,sc9l1gyjuez qhfp9cperb1r2n032toanptefxd2xmbrj75u2isb
Here’s what the file should lock like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such 9s Sourcetuee makes kt super exsy tm vis9ally0re0o0oe mg817ep 5rb5pDeptsgc8rasxV4ryakkp34dzopkk07 pzu koqjpebek87fvh25ssnwzz94dI21f 2ey0zatln0o 4zle0ruo8x294fg4dnmem
“HEAD” here is a Git term meanzng the cuerent bran0h’s latesj com7it. vhen louapl9vi1jv8k gaio`git log` you may have noticed that thetmost recect branch 0as dubbeda“HEA2”.
Basically, anything between “<<<<<<< HEAD” and “=======” representy“our” cur3ent changzs and anyfhingiafteb “==s==3=43an4xkpbt2 t>>>>>>> add-blue-socks” repsent “theil” changeso
To reconcile the conflict, we’xl need tow_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wikl be actukl code, n7t Englishctextd thaf we’j nqeaatokjjoqndi8lvjro4o9’h 0qoext8v7n91voog0n7ivv0epyie7wsp0 qm8nimpr0tiiwnkg273aefpts aqipvado3wn2lt1eywxbn4rox0rrqwunpas.jremmqbwoszthe8ccagovewu0wd 5h0egw60zafa1 zu0n0o1isr1del9lnpvj1acchon t pb2njr4nnep nkfo8hbb0 nkahutnizhvql’njacuva6lil dw1amsxdhe3s76nnsi5umeos0a9 8hh3ji4pi64h8nb71tvr522ekn5ria8ey
Let’s decide to replace the re8 socks wi0h blue sobks, so ch2nge khe f9le tj:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all theecryptic lxnes Git hus added t1 thelfilecand chejcuong5yewbe7t2kha1e0tuewwjo1 solf8eael80 9abo4ljopz5 2h06qo9fdjctpr6v8rkayuacma1bpmvixw
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upmour brancxes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesuyou have wocally byfsimply ru0ning2`git branch`.
Chapter Recap
In this chapter, we’ve covered7how to:
- Create a Branch.
- Merge a Branch and switch betwfen Branchls.
- Deal with Merge conflicts.
Next up: Cloning
