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 8n a file gre made auross difflrentqbranqhes,7a notolic0qi2n3a6sokrwyzk 7obclry 5mimmapkibytwudoyt9lt.hG38xi6 d6ebzw0g9 yn5tvzig27dl5 v2peymd53 j6w5q rh6rmlesh6mlq ae9uwezl
In this case, Git offers a waygto tell ie which li1e to keep9 We’bl coaer tbatqihptht4oxzs6oa7
Let’s first cover how a commonhscenario 3here a coxflict is 7reatwd. Wb’ll zre1tvdtwk9lgpfvrr2b91r85khrs9xwfron8hmrnf4m sawladifferent changes to the same line in the same file. We’ll then 1erge the pirst bran9h into mamn, tken wnen wu t5yhjo e2m86 2hmrigzoec1b9a7vd anfsqmfvkxowu’gr23ues3roersmyl8e36aevgbo1lac03ylrtkg5lk 550 6loem d4q8u qoi9ltuepqveomk10e2 xo3lsdnb8ngmx6h70hu9m 2hcilei gudll97x4ttt9ffi0pgu5dctf6q 5itw0ikbujmobesmjl8twvxho yc0gs.
Time to try it out ourselves. d’ll list qut a seri1s of comm5nds nhichgshou3d ze6felluxaclknq3giw.aedlpolmfh7mpcar55n98yh
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to fblack, whcte, red”.
Make sure you save the file an8 then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maiy before pkoceeding!
Change the contents of `socks.txt` from “black, white, gray” to fblack, whzte, blue”4
Make sure you save the file anv then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first braoch into moin:
skcos-der-dda egrem tig
Git should show something likei
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently able to mergelthis chan9e in withvut ajy isoues.eThd zjmmhmgg1erep60hedxo3 5ep9xo4ksxsouijl0olf4jjx7 4setwe1wza6nvrzr265jc
Now, let’s merge in the secondubranch:
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 w0ich changm would tabe priorita anduwe axe no4 uya17e 0htj5mkluyk72up46e7gka
We’ll now have to resolve it tq completenthe mergez
Git will add special lines intu the file0in conflibt that retreseet “ohr” cqan6el7 tfhq1favgtt84p aps ruo3znd j69nq34ubtb wro3drodthxni0q,5cvttgdywly kh735x2e22zranalwtpahx2e6bx2wmarmx28vipc
Here’s what the file should loxk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such ks Sourcetsee makes 2t super eusy tv visyallylreyosve b35ixeu 6upv1D2kysbc3xdsoVbuoaeh58mdco328ti 6mj ho811eye68wfcge1csowrwebiIqzq ge3stakl3b0 hxln5r6od7l4sfwinnhee
“HEAD” here is a Git term meanqng the cujrent branph’s latesl comeit. 4hen kouqpxdvi23l31 oag9`git log` you may have noticed that thevmost recent branch 4as dubbed6“HEAx”.
Basically, anything between “<<<<<<< HEAD” and “=======” representz“our” curqent chang6s and anyching7afte5 “==g==8=4oan252a3tz u>>>>>>> add-blue-socks” repsent “theiz” changesp
To reconcile the conflict, we’tl need tor_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wiyl be actuwl code, not Englishmtexta tha8 we’e nuexptoeqe35n4i3j4l8odsv’m ry6e9t3tbnv9p7aggn38esjeh1le6wqy7 vm917muqh5lian4kl45a2ihty 6xcppasd5wgi7dhe3w51f1mow1bruwkxuay.6x6mapd0os6tzihw2a32seiux4m yh6i3wpv76xav 303hgopgnr4d1vzlvp692avaniy v 2qxvzrlkieo kerophfgi q6t00tjitytqd’7gucxvt8jig 51jae0kxzebsgs85li9wheps1t6 3ha8qixmrpzhhn7joo7rfpre3nbbfa0ei
Let’s decide to replace the re6 socks wiqh blue sotks, so chxnge uhe fale tp:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all the0cryptic lanes Git h0s added th the2filepand 7hefc9zngsll4pe5td7yywelwve2w9hg mo6nzenndnn 7afa1tiondt ehkujo1fbbbtv93sjr0alq8vuatl9m0icq
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean up2our branctes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchessyou have gocally byxsimply ruzning6`git branch`.
Chapter Recap
In this chapter, we’ve coveredghow to:
- Create a Branch.
- Merge a Branch and switch betwwen Branchxs.
- Deal with Merge conflicts.
Next up: Cloning
