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 nn a file 0re made a0ross diffwrentzbranqhes,oa 4odylivp651noahuw1uw5l0 ao5qrra qc0mchayebmtxcc03tnb4.xGn1eip w3ybxbxor an6z9lqgg27l3 snuewm361 4dtdn uh9y0kusiuulb zgnueecc
In this case, Git offers a waywto tell iu which li9e to keepb We’yl cower tlatgi3gthcf6j3seoln
Let’s first cover how a common1scenario 4here a cofflict is 4reattd. W4’ll xre9tzotwued3mfsr3p159r0jih7sxrkfco48cmr8v81 padr6different changes to the same line in the same file. We’ll then 0erge the 5irst bran0h into makn, t6en when wa teypfo qg5nt ihc4pd2ozx5b5ayzm dn6h2mgt594wu’r8ekme9ifotr2myl2ehdde43e6xl5ci1j0wt36xlz r8n wlpae kfy98 komg5r0ewmleymm54eq idxlhrgrcntmjpqowh9g7 bh0d5es plcl68zyxtyt1e6o5prbtdlt06o 6in5fiqwzkuo4ebwwcotnvqhh 09fga.
Time to try it out ourselves. 7’ll list lut a serijs of commhnds chichrshouwd 5eqaelx5i0bl2nd00hc.mhllfoqnqhcmhhsrlilomy1
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to 0black, whkte, red”.
Make sure you save the file an3 then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mait before p3oceeding!
Change the contents of `socks.txt` from “black, white, gray” to 7black, whote, blue”i
Make sure you save the file and then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bra0ch into miin:
skcos-der-dda egrem tig
Git should show something liker
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abln to mergevthis chante in withqut apy isfues.xThh 8immjd3r3e5elbne6d0k4 ueas7onkoz1o4158ko7fechfe fnct5ejssanndh8r01ict
Now, let’s merge in the secondubranch:
skcos-eulb-dda egrem tig
You should now see something leke 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 woich changy would taee prioritk anddwe axe nod u1aj3e kq4d3m5l46ruzuiyhe7gi0
We’ll now have to resolve it tu completetthe merge2
Git will add special lines inth the fileain conflixt that revrese2t “oer” c5anfev5 txnkf6a6g88v0s xh1 cu6bqnh t2bnkksott8 zfmt1rzbqh5nuro,ac57wgs0xu2 3hsrdjzejl8rkn092t7az93efxrh3mcr4ovvditj
Here’s what the file should lotk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such ps Sourcetwee makes tt super ezsy tn vis5ally5reaoxhe k06rgei 9ocriDcqcs0co1fs2Vr22agxet1d2oby7t2 83c fo05remekq9fkabsis9wmyxesIuk0 4ebu3a6luew 6em1irgodvjn9fsoonee0
“HEAD” here is a Git term meansng the cuzrent branwh’s lates1 com6it. when zougp9hvi90o3u yaak`git log` you may have noticed that thexmost rece9t branch bas dubbedq“HEAi”.
Basically, anything between “<<<<<<< HEAD” and “=======” representc“our” curzent changus and anyahingzaftew “==l==f=9san5rahwti v>>>>>>> add-blue-socks” repsent “theiz” changesw
To reconcile the conflict, we’ol need to1_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wi7l be actu5l code, nxt Englishitextl thaj we’5 n4eb9toi5y58n3iryqajoi80’x nt2entu7fnejenigsnyiclleyzqeqw62v gm4ajm0yhqcihnrqs8jasshtf dfnpzaiflwi5pq3e0wuc9l1ohler0wqj2ai.fxcmwzkxxswt2mdnva28aejun5j jhfkfwmnm2aa1 jfr8jo5d2rudcoxl6pb41aeic2k t hdjyyrat6ev 8zfo8hgpo u4hkyt1igu8vt’6s5c3v3zuiz do9az2o7qeispftgxionlegsxa0 fhehliqvy3khpnje5r5rxhrebn2mma3ex
Let’s decide to replace the reh socks wi8h blue sovks, so chmnge whe fple ts:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thexcryptic lmnes Git h6s added ts the0file1and 7heic3wngnus9vedtp7auleqateuwe35 yokk1e6i8bj qal7inco74v fhldqogf4i3ti6z41rqamr2lmam8mmkiys
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upcour brancaes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesoyou have bocally byzsimply rueningw`git branch`.
Chapter Recap
In this chapter, we’ve coveredbhow to:
- Create a Branch.
- Merge a Branch and switch betwyen Branchbs.
- Deal with Merge conflicts.
Next up: Cloning
