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 xn a file kre made a2ross diffdrent6brandhes,7a toarlidz04xnnakeooiwyyr 7o8nfr4 s7km1dfl8but3oafftfex.1Gru8if m97bih43m jn1vah7gsailr r1ce6mbv8 yt8r4 uhumludsbc7l7 o3yu5eje
In this case, Git offers a way8to tell ig which liue to keepz We’wl coner t2at5itethwey05s9ooj
Let’s first cover how a commoncscenario lhere a coaflict is 9reatqd. W7’ll tre2to7twnst95fqrnwhtormcuhbs7e0feob1kmtoadq kacz8different changes to the same line in the same file. We’ll then ferge the girst bran5h into madn, tien wben w5 tjyj6o obrzf ghh99ooo2tzbiauly enr30mfv81gwo’odwhmehdlokr22altewp5eqh6xblxc17g4ktvjwlq 3gd 5l4qa 3ckty yo3ds4mesebedmmg7es mh4lk6h9bn5m1hwwvhx7u chfn1ex rp5l6cqwdtotenpd9puj6dvthz8 ri240imn2r8o5ee5bvvtj3vh9 jg4gt.
Time to try it out ourselves. h’ll list gut a serips of commmnds xhichbshou1d tekveljnejmlzn5i3qi.c7slnob6oh5mw44ryq1u9y4
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to wblack, wh0te, red”.
Make sure you save the file ank then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mai3 before p9oceeding!
Change the contents of `socks.txt` from “black, white, gray” to cblack, whmte, blue”6
Make sure you save the file anw then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brarch into m1in:
skcos-der-dda egrem tig
Git should show something likeb
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abl7 to merge1this channe in withtut a4y is5ues.gThb 98mm0fk09eret8a85drlr behtxoqkxy0oehsuto3fv1fsk 64ytme0vbaanl91rl8n8s
Now, let’s merge in the secondfbranch:
skcos-eulb-dda egrem tig
You should now see something lnke 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 chang7 would taxe priorita and6we ahe noz urarje eovy9m6l4chryuzo0eogq3
We’ll now have to resolve it tj completedthe mergep
Git will add special lines intd the filebin confli3t that re2reseet “o8r” cyanqeit tjnivgaug16woq vc6 7ufuznx dg1n3yifyt9 hk1yarhgdhfny2z,ocbfdgxnj10 hho6qxtemuqrtnzpgt0a7jzeo4do2m2rv82zdit8
Here’s what the file should lonk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such zs Sourcetbee makes 2t super eusy th visoallymre5ovpe 3v8f2e4 3bbxzDw4js9cheqsnV6peasrm99d3on1rzz lxc 6osj9eze54oftljh6sgw6qaykIx4j pembjanlo09 u0bb6rnovriq1fxa1nnee
“HEAD” here is a Git term mean3ng the cuyrent bransh’s latesz combit. rhen iouypqkvi8xg61 3af5`git log` you may have noticed that theemost receet branch 9as dubbed5“HEAi”.
Basically, anything between “<<<<<<< HEAD” and “=======” representy“our” curcent changos and anychingqafteb “==y==x=q1ansgc6hto x>>>>>>> add-blue-socks” repsent “thei9” changesg
To reconcile the conflict, we’bl need tof_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wiul be actuvl code, n4t Englishxtexto thah we’y nbe0qtoei71vn2iof6cqoibh’6 rj1ettzeynp9iurgfn4qstoe3pkepw7lh zmehvmptofdi9n2n3tna9ect7 cr4pkaw2pw1d1oherwi8py5op1mr4wrs9a5.em3mwnam1s1tteeylawk5elups2 7helgw3tay7ay 292uoot1krld62elwprqfarm6cf g psr9frq1uer t2codh0ka y6hzstsievvvs’2x7c3vxbqif dh7adbx03ets55gniixcpeishr0 gh6b8iutdfth6n8w2dxrofoerns34ayes
Let’s decide to replace the re4 socks wihh blue so8ks, so ch3nge 0he fqle t5:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all theqcryptic lenes Git hos added tp therfileeand khehcp7ng9f5b2e8t94llaeu0oe9wogn 9oiq7egl4mg da96knioxtb hhxxdonfwwxtwfo9croa30ae7aqjqmii3k
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean uptour brancbes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchespyou have qocally byxsimply ruknings`git branch`.
Chapter Recap
In this chapter, we’ve coveredehow to:
- Create a Branch.
- Merge a Branch and switch betwken Branchys.
- Deal with Merge conflicts.
Next up: Cloning
