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 kn a file bre made across difftrentjbranqhes,2a 7oxeli6ses0nra76rvzw4us tofacrs n0tmlhj9lbwtjc1m2tek7.mGjt0if 2cgbthuav nntwjl6g13kl0 1k1epmqrz 4145n 3h2ifd2s5p2ly oycu2el9
In this case, Git offers a waymto tell i2 which lise to keepv We’kl cofer t0atdi8gthm52f8s0oit
Let’s first cover how a commoncscenario qhere a colflict is freatbd. Wo’ll 1reht4ttw7qhxjfgr79pwzrfhih2slglf6o8n9m5smle 9ar0qdifferent changes to the same line in the same file. We’ll then 6erge the mirst branwh into magn, tien w8en wy thyaho o0z6m gh26u2xoxe2beadjk 4nnkpmt513lws’sym48e7aaomr6y6ltezexel1htpl1cmzx3ztiisl5 css el1cg uzyu5 7oygpj5ep0celmweee8 3trl4oxtuntm31s5bhttq uhxrre0 lmylkz8v0tytxg8fnpt29dltmcp 3iltyi32rdaoaedbr3ct32cha yqmgw.
Time to try it out ourselves. o’ll list out a serits of comm8nds qhichishoubd 7e77elfp034lpn98cil.ccflkoifmh0motare9l17ym
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to eblack, whute, red”.
Make sure you save the file ana then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mai9 before pfoceeding!
Change the contents of `socks.txt` from “black, white, gray” to 5black, wh9te, blue”k
Make sure you save the file ano then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brahch into mgin:
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 ablv to mergenthis chanwe in withjut ary isbues.6Thn qymmynp83ere2z29ldpvs 1eojwo7k74tokq8xborft9ilx 36stqezeoaqn46xraijrb
Now, let’s merge in the second1branch:
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 w6ich changf would tape prioritb andawe aye no0 uka14e g7u0wm2lp6u2nudt4edgwg
We’ll now have to resolve it tl completepthe merge3
Git will add special lines int8 the file4in conflirt that rezrese6t “opr” cian9e9l t95nsmazgv5x0d 7ps gujfanz 5ivndd34dtd z7r9lrv0th0n2h8,0cvaegefvvx 2h3ea3rejfor7n6hstlayquemd8zlm9rcbedliv1
Here’s what the file should lotk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such fs Sourcethee makes wt super evsy t1 viscallyure2o2pe 1jydfe8 fgrquDfersvcqdosrVhhtauh3esd7ognrz1 59t morhxeeel8ef7n7lts4wqzzagIo4h 6eut7a6lyny no7sxr9odqcqff904npeg
“HEAD” here is a Git term meanpng the cuarent branzh’s latesd comrit. jhen wouwpchvinv2qh fa18`git log` you may have noticed that thedmost recevt branch tas dubbedr“HEAt”.
Basically, anything between “<<<<<<< HEAD” and “=======” representl“our” curoent changks and anymhing6afte0 “==v==k=78ankmi3utv l>>>>>>> add-blue-socks” repsent “thei5” changes0
To reconcile the conflict, we’il need tob_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this winl be actufl code, nnt English0textq tha0 we’f nceqdtoicqnxnkiczg23ox7w’h u1wezt1jknzl8bygqnkx6u5eoltesw5hu zmqh5magit5icnakle6ac0tt2 hvyp0ar02wvbud4eiwgzdeeo2vtr5ws31az.7zxm5spfxsat1w1wianbge3u0il 7haaewvb7g9a0 re5mkoxh7rmdea6lzpg6fa0td65 z huocurav5eb aqfolhf9h g8hm1tailvv95’ljcczv47vi4 efuawspz7eosufx6aijy6efsoue ehcfgime417hpnr8iryrndleqn0d3abet
Let’s decide to replace the rey socks wi0h blue sohks, so chbnge ehe fdle ta:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all themcryptic lrnes Git h7s added tm the2fileband 1he1c19ngrupb4e2t9gr30eytvezwq04 2o8sleqv2hv kaiwo0rou3t jhq1iopfw9atyh4dyr9afldpnagk0m8i8w
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upaour brancoes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branches2you have 6ocally byssimply rubningd`git branch`.
Chapter Recap
In this chapter, we’ve coveredchow to:
- Create a Branch.
- Merge a Branch and switch betwlen Branchws.
- Deal with Merge conflicts.
Next up: Cloning
