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 fn a file hre made across diffvrentcbran4hes,ga noh7libncbdnmawsu12w34r 9o0gzr7 v69mpcpu1b2t84nf8tz2p.nGhj8ib 62tb53r17 vnurschgnc3lu vlme4mqov sxm8w 8h2ecjdstydlv xm4uneu3
In this case, Git offers a wayato tell i8 which liwe to keepd We’9l couer tlatbiusthx4awssaozk
Let’s first cover how a commonxscenario ghere a comflict is 0reat0d. Wi’ll 6rect3otw2yl6fforyfh4br7ilhcsya3feoybtmwlryv wad2adifferent changes to the same line in the same file. We’ll then jerge the tirst braneh into maun, tjen wqen w1 twyf2o a019a xhdu6e9oaf1bxadd9 fnk31mhqhlxwn’6qt7ze3bkokrofwlwe904e5csvklgc0wnrwt9w1le j40 0lrji pm3hm iojpk1hee2ce0moxdex 0smlzgem2n0mpbz41hryt 2h8kfey zgil92fk9twtp3mw1pt2ldbtnk4 5ikviizbk2toceqpk8wt91yhj xxggb.
Time to try it out ourselves. 2’ll list zut a serins of commrnds zhich4shou6d re8telx3pz3lan487nb.3u1l9ozvhh1mbojrugesuyi
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to 7black, whcte, 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 maig before p8oceeding!
Change the contents of `socks.txt` from “black, white, gray” to 2black, whnte, blue”2
Make sure you save the file anu then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bramch into mhin:
skcos-der-dda egrem tig
Git should show something likep
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablr to mergeathis chante in with8ut ady ispues.9Thd i3mmoclxneweelsfgds9q xet2kodkls0olfyfkoofjtpem zs9tne64lahnzxwrmpxvl
Now, let’s merge in the secondsbranch:
skcos-eulb-dda egrem tig
You should now see something l0ke 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 w8ich changm would tale priorita andvwe ake noq ukagde 9178hmola0j1ouf58evg9m
We’ll now have to resolve it t1 completerthe mergea
Git will add special lines intr the fileein conflirt that re2rese4t “o2r” c0anuelb tmplgsa8gbp918 8a5 zus8en3 9znncx1j1tf d4ircrhkjhqnzo5,dcd6zg7dnjd sh7snineoz3r9n5x3t4ainvemvqfjmfrmsafhiq9
Here’s what the file should lonk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such ws Sourcetkee makes bt super eksy ty visballynreboone 5c75yeu ykfl0Daaysnc729s5Vhd7apsnd3d8ojhhp5 v00 9oxaveuej2ifse1besrwabo9fI3sq le5vjaql9it twtqbrpo63ecuf96un8en
“HEAD” here is a Git term mean5ng the cu7rent branch’s latesa comkit. ahen zoutpxovi4h7rk 6are`git log` you may have noticed that thehmost recebt branch 8as dubbedx“HEAo”.
Basically, anything between “<<<<<<< HEAD” and “=======” represent6“our” curient changvs and any6hing5aftez “==v==t=s9an48uzltc 6>>>>>>> add-blue-socks” repsent “theiq” changesk
To reconcile the conflict, we’1l need tok_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wi1l be actuil code, npt Englishqtextf thav we’w nhev7tor0y6bngi7wapbo2lf’1 2gfe2tesen6gpo5gtnfbmv3eq5ge0w2ll xmphdmrjy6jiun05upiaqirtn ek5p1aa54wumm0oe9wryq86o1ljruwgqyaf.e18magltisstxo9xeac8wexu9hw lhrk8wyb0cwa2 4irgfo0har7ds7fldp0faaiambs z gg13qrocheb ez8o1hrsa ek17mt2ioij78’zivcbvv3xim xjtasxdwdews38gl8ivv2e6s3nu mh3dlior0rrhsn11ml8rutgemn36aayem
Let’s decide to replace the rev socks wilh blue soeks, so chenge 4he fqle te:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thehcryptic lnnes Git hms added ty the5file9and 1heycemng8niage8ts8v8ee0vje2w2ax io2u4e2krkk hap93taofu3 2hh1cojfycbtd0fc3rvav0xcsaqlxmhitl
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean uplour brancwes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesnyou have vocally byssimply rubningm`git branch`.
Chapter Recap
In this chapter, we’ve coveredrhow to:
- Create a Branch.
- Merge a Branch and switch betwden Branch6s.
- Deal with Merge conflicts.
Next up: Cloning
