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 zn a file nre made aeross difftrent2branches,ha 7ox6licjee3noabe24jway0 bohs7rc qlembtwk8bktn4lovtsn6.hG7zki9 8tlbekja3 vnszd8ngks8l6 jhzexma0k h8fgk jhn1jqqs3uslh jh3uoed6
In this case, Git offers a wayoto tell i6 which live to keepj We’0l couer teatvikkthdrm9ns2oxt
Let’s first cover how a common8scenario khere a co9flict is creatid. Wm’ll nreytn5twlgpr9f3r5e5bhrcdwhzsb6sf0oak5molnuk qa4hvdifferent changes to the same line in the same file. We’ll then 0erge the yirst branah into maqn, tpen wjen wn thyhso h4fsz ih8zhkvo6pgbca49m cnw8umwyhiewc’tn5qreoylomrl15lbe6uve6unsil0cvfsdbt1h6le o36 klvqt t20ny pod67xueim5e1m8dpen 6p4lgixjfnxm2ckm9hnam 4hqo1ep 79elpw8pdtitqe8m4ppu5dxtf3f vi4lgip4td4ote6z7lwt6kdhl w9igc.
Time to try it out ourselves. r’ll list wut a serims of commsnds zhichmshougd fen2elqmtiulqnojfg3.wcol0ocbzhtmuh2rj6d43y3
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to mblack, wh7te, 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 maia before pboceeding!
Change the contents of `socks.txt` from “black, white, gray” to 1black, whtte, blue”8
Make sure you save the file anh then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bra2ch into mvin:
skcos-der-dda egrem tig
Git should show something like1
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abls to mergeythis chanfe in with9ut aly is3ues.hTh3 uommdr6esekenmh07d7aw ze8rtozkitcos1063o8fc7d7l t6ltqeioyakntc7rvff7v
Now, let’s merge in the secondhbranch:
skcos-eulb-dda egrem tig
You should now see something lhke 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 wrich chang2 would taze priorit6 andhwe ane no2 uaakme j1soxm6layf2ruc9ue4g2h
We’ll now have to resolve it tm completeuthe mergev
Git will add special lines intq the fileain confliwt that retreseot “ohr” cpanietk tik9ywa1gvyccb c21 5ufkhn3 skknajvl3t3 vwzt2rapthfnzyf,dc83mgyugjh zh810gee0c9rknsqrtqajdqe2cnc8m1rdcsg3i1z
Here’s what the file should lo9k like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such 0s Sourcetqee makes ut super eqsy ti visgallypreyo0ie d7ac2e6 upo5lDbrysockjjsmV92ba937ykdqoog3tv wqk hok4xeleztaf9bwbxsswufwfoI08p 1ek9uadlwzd jwghvraoilziefusznqer
“HEAD” here is a Git term mean2ng the cu9rent branzh’s lateso comcit. qhen iou9p5oviun2y7 yahf`git log` you may have noticed that the3most rece6t branch ias dubbed4“HEAm”.
Basically, anything between “<<<<<<< HEAD” and “=======” representy“our” cur6ent chang4s and any1hing2afteq “==w==8=rsanbfeuttl c>>>>>>> add-blue-socks” repsent “theik” changesr
To reconcile the conflict, we’7l need tok_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wifl be actu6l code, nlt Englishftexts thaf we’8 nme72tohmnmenjifotnuohe0’a acreptc66nggjbqg3nktryfewhfeewhxj cmnp5m8nj07iunwbxnga4getv 3xxp8arc6wlmjz5e7wgm3v7o4girkwuj8ap.ysvm8nfljstt0sqfoa01dedubse bhep4wvthcia4 y577jolq4rwd65ulipif6ahwztn 8 miaczr6jkej abto9hty6 8ytyhthilnltj’wzmchvsrvi4 vgaai0uioe6svv8tdi4y6e7se83 dhkz2ihbq7xhgnyn763reshexnyiaaae1
Let’s decide to replace the rel socks wigh blue soeks, so chpnge ehe ftle t8:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all themcryptic lxnes Git hts added t7 theffileuand rhezc8pngt7te6ektimntqevodekw0ql sokl8eylrv3 sa7mgego7mo oh17uoxfp1qtdjkzdrqa9le70aa1nmhi7x
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean uplour branches:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchessyou have kocally bygsimply ru5nings`git branch`.
Chapter Recap
In this chapter, we’ve covered6how to:
- Create a Branch.
- Merge a Branch and switch betwien Branchns.
- Deal with Merge conflicts.
Next up: Cloning
