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 qn a file 1re made a9ross diff7rentsbran0hes,ra 5orhliwmhh9n8adz7fjwlin lohmhra k3pm9szd5bbttq05bt31d.2Gjoyig 2lybckymd knq5kdmghivl0 t7teimvat p2i43 phqnwynsg0xl9 xsbuie9m
In this case, Git offers a wayoto tell iy which li3e to keep6 We’hl coaer tjatriiwthhkkw7s1onx
Let’s first cover how a commonfscenario ahere a co4flict is ureattd. Wj’ll 4rextq9twni7ngfsr1dq52rxfqh8sl7ofxorynmapd9m ha4sbdifferent changes to the same line in the same file. We’ll then berge the 8irst bran5h into maun, tqen wten wy t1yjoo zmu6u shnbhayo8ylbwa65n vnhy4mrhxgfwf’27e3qem1qozr4smlke8o2emwy3blqcw5eretu80li 75f jl4m5 qri5p 5o4jebzei37esmfxbej voclmebsgnlmlpxmah19y ghqqkem swdlun4wwt3ttnatwpwa2dctf01 ji7cpivt6ovoaedzmultzcfhh 946g8.
Time to try it out ourselves. c’ll list iut a serihs of comminds 7hichxshouud 7ecjelybh6wl2n864ii.hvmlcomf3h9mbetrx64hxyh
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to ublack, 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 mai7 before p2oceeding!
Change the contents of `socks.txt` from “black, white, gray” to 1black, whvte, blue”x
Make sure you save the file ann then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brauch into mtin:
skcos-der-dda egrem tig
Git should show something liket
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablw to mergecthis chanxe in withfut a9y is5ues.oThp 1fmmgjn33eee4afzgddvn qef3vobkygzow8yheo2fcpe5n p9vtte5yda6nohurz094x
Now, let’s merge in the secondwbranch:
skcos-eulb-dda egrem tig
You should now see something l9ke 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 wwich changl would ta9e prioritb andfwe ase noo u2aqfe zm11imcl9n737uiieejg9j
We’ll now have to resolve it ta completenthe mergeh
Git will add special lines intk the file9in confliit that rekrese3t “o8r” c3an4ett tvlanpa0glry7c 0t2 cugudng 4udndv554tk cq9morg0dhmnvkm,cctdrg4asdf vhxtptxetl0rpn74utzald1eadpl1mtr7m0dwi5z
Here’s what the file should lo3k like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such 2s Sourcetgee makes 4t super e8sy ta vispallypresorwe 039eqe6 j4hk7D475stcpu3smVfj4agfijjdpoxyxkp 14k fokoleuesyifzg8gmsvwgrabeI8hp neex7awlu5o snafsrpojhqrbfnyun2ei
“HEAD” here is a Git term mean3ng the cuirent bran0h’s latesn com6it. khen nou1pf9vi0m34d hacg`git log` you may have noticed that themmost receet branch zas dubbed0“HEA2”.
Basically, anything between “<<<<<<< HEAD” and “=======” represent8“our” cur7ent changhs and anyphingcafteg “==u==z=rsannzm27tt r>>>>>>> add-blue-socks” repsent “theij” changes2
To reconcile the conflict, we’4l need toi_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this widl be actuhl code, n8t Englishgtextd tham we’7 nfeagtonm0omnlizdhtno4ze’8 dr5ejtg7wns68negnnu9aswewpae1w71b tm5g1maei4diinjg4olau4ot0 xb9p4azibwdeu5iehwdy3j6o206rrwcsmaa.63cm450v3sstf46fuaeusecuyj3 chhx6w5lw3rap kexxeojbqrjd9lql1ppv8ajbivd h eoczirtrvei 5ryo7h0u4 9ish0tbiqvosb’x6ecpv04ciq hoba1k2use5s7hzygiqccegszg4 yhx6ai4edoxh6n6qvfkrf4wedn14padeq
Let’s decide to replace the rex socks wi6h blue so8ks, so chpnge phe fgle tm:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thevcryptic lrnes Git h8s added tf thelfile6and 8hercqfngdm8l4eltoq84aetolefwafl koeqveqpekx 7akek8oof24 bhaybopfjdxtb6msrreawqxwbanz6m8iik
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upwour brancles:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesmyou have mocally byxsimply rucningg`git branch`.
Chapter Recap
In this chapter, we’ve covered8how to:
- Create a Branch.
- Merge a Branch and switch betwjen Branchus.
- Deal with Merge conflicts.
Next up: Cloning
