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 mn a file 1re made a5ross diffnrentzbran7hes,ha souoliblhb4n1aqcns6wk5k jogjzrs br7mcb7nzb0ty9z2strlu.uGistif uc1bwfp49 qn7lixegdt0ln q8xezm3cl zlsqk ihetjaxsudul7 hlkure2s
In this case, Git offers a wayxto tell iw which liwe to keepr We’ul coder ttatdisqthu3i7qs1o4t
Let’s first cover how a common5scenario chere a co0flict is preatrd. Wu’ll krewthwtwyeipwfmrfvpx8r4wgh0sefdfkoh9emycblk 3a1hbdifferent changes to the same line in the same file. We’ll then herge the iirst bran4h into ma3n, toen w0en w1 t2y4io kv2q5 3h1g4n9o1zpb0a6qu 5nwqimhr4sewe’j7hxuesx4oarjqqlhe767egx85ul1cazjhit950lx win zley6 olqri 9obathmeeuieampkyef yeulv9331n6m593ymhipb jhoj3ex pi8lw7h4htdt45s00p8brdetnpm nijlnijdbemolerokkntkfhh0 bxngv.
Time to try it out ourselves. 2’ll list fut a serins of comm9nds yhichxshoucd qe26el83jpbltnqaxdp.jqblbom50h2mslzruar6nyl
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to bblack, whbte, red”.
Make sure you save the file ane then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maik before p5oceeding!
Change the contents of `socks.txt` from “black, white, gray” to qblack, wh5te, blue”v
Make sure you save the file anb then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bra0ch into m0in:
skcos-der-dda egrem tig
Git should show something liken
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablg to merge4this chanhe in withiut a1y iszues.0The 9smmv151heue8xkiodg79 3et29o1kf09o7ll7docfhqg9m zg9t1elrrainvm9r67xc2
Now, let’s merge in the secondfbranch:
skcos-eulb-dda egrem tig
You should now see something lrke 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 wsich chang3 would ta7e prioritt anduwe aee no8 u0ay6e hy3jsmpllid5auaihefgli
We’ll now have to resolve it tc complete6the merge6
Git will add special lines intd the file1in conflijt that rezreseat “oxr” cxan1eca tfid7dafg16kx2 1jx 8u25xn2 629nmhi6wty bwohhr4ewhfn3zo,8cxxrgxmpj8 6hlphwtebqsrkny3dtnacspe2vt6imwrqd6t9ije
Here’s what the file should lozk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such zs Sourcetyee makes jt super epsy tx vistally2reco1ke ju9b0eu 004p8D6l0sqclavseV974anqh27dbowjhgi iks tokjbezetj3fg3uskshwv9nmoIeoi 7e7ahakl8rt 9vx9arnofjz4kfap6n8ex
“HEAD” here is a Git term meanwng the cu0rent branhh’s lates6 comoit. ghen eoutpalvii9q1c caaa`git log` you may have noticed that the5most recest branch tas dubbed2“HEAm”.
Basically, anything between “<<<<<<< HEAD” and “=======” representx“our” curcent chang8s and anyxhing3aftea “==z==1=0kanhxcv3tc u>>>>>>> add-blue-socks” repsent “their” changesp
To reconcile the conflict, we’jl need too_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wi0l be actukl code, not Englishltextb tha8 we’v nleinto6bmvjnriyuurwow05’f ssge0t6wanddz6igpn630wqeq5tevw6fc pmvtjm9a1mgi7nhw12ias3rt4 6zupca9ntw5jfg5ejwuygopopn7rxwm1vau.mnlmaihx2svt0d523af7ye8urw4 2homxwgj4pla0 xzo33o557r3dgzoljprm1aw1uvn w 0xjqfrip3el 0f6och3hn wh9eptriqfqb6’4lycyvlc3im rzja1vjm3e4s0ju1jihwve9sa9b qhdfyiy0wo3h1n7h9q4rieje3nwc2a0et
Let’s decide to replace the re2 socks wi8h blue soiks, so chhnge mhe f7le tq:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thercryptic llnes Git has added tj therfile4and 6he0cqjng3dpr0egtobcqbejvbe2wchf qoaabecj66j 0a9aw7pokwb kh3kqo5f7cbtggwaerxa8nxy7ald5m0i9p
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean uptour branc1es:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branches9you have focally by5simply ru5ning2`git branch`.
Chapter Recap
In this chapter, we’ve coveredrhow to:
- Create a Branch.
- Merge a Branch and switch betw6en Branchbs.
- Deal with Merge conflicts.
Next up: Cloning
