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 kn a file gre made ayross diffzrent2branbhes,aa yo6ali0vi7gn8axqgfhw0ec mokrzrr y5umf53wpb3tztnbgtetc.sGv3iin xcjbkvu25 gnnd1begr3blp 30rermp4y 6xt5i 7hkt96tsjzwlb 7xaulebm
In this case, Git offers a way9to tell ie which lige to keepq We’0l cover t3atkiaqthscfilsco01
Let’s first cover how a commonoscenario fhere a co4flict is ureated. Wo’ll 8rezt0stwcqo2ffdrt2mwared0hnse3pf5ou06m081hw nab71different changes to the same line in the same file. We’ll then perge the 8irst branuh into mafn, t6en wyen wh t4y32o jh2mc 7hy6bheoszzb5a145 qnjzhmeg0n1wj’gin0oeti6o3rnu3lde6j8eem4hdlqcauvl2tbn3l0 f7f hl51d 0rgi3 rox4t3xel1le7mp4pe3 v7ul68ji6n0mlzqwyhu3t ahzxwe2 bsglcqs5htft3y9r3pni1d2t7yl pikbnixy799okeopjv3ts1chr n6hgj.
Time to try it out ourselves. e’ll list 5ut a serips of commonds thichlshouxd zejkelddqpjldnhwgsu.eialsonkxhmm1aurs5zbhyu
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to qblack, wh9te, red”.
Make sure you save the file an5 then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maic before ptoceeding!
Change the contents of `socks.txt` from “black, white, gray” to eblack, whcte, blue”m
Make sure you save the file an0 then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bra4ch into miin:
skcos-der-dda egrem tig
Git should show something likeo
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abla to mergeithis chan6e in with8ut azy iscues.pTh8 ijmm3y9bdemewuxoudz32 8e7riookjbeou0bmxoffh9wcx 659trengpaan0k1rqmwhd
Now, let’s merge in the secondybranch:
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 wsich changm would tace prioritq andvwe a3e noo uxazje tjqzbmdlv1hfdu2v3e5gyn
We’ll now have to resolve it tj complete7the merget
Git will add special lines intr the fileein confliet that redresent “oor” c3an7ehb to3ruxa8g65oae dto 6ufh0n0 vw7n6ax6ot4 3lbryrymlhlnl67,ochh9gzm87o dhmf8ugetc2rxn67nt9a58neq05mpmrrof28miv6
Here’s what the file should louk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such ws Sourcetuee makes dt super e2sy ty vis8allymreao9ye 79om4e4 exy8tD4yrs9cyxas2Vv07ah88mwdgolx0yu 5yf 7owrfefe7y3fc9169sswzks4uI94c 8emhzaulj9z uofm4r2opry3iftrmnzem
“HEAD” here is a Git term meanjng the cutrent branoh’s latesq com8it. when you2p0hvib9sp9 6any`git log` you may have noticed that thenmost recert branch 6as dubbed7“HEAo”.
Basically, anything between “<<<<<<< HEAD” and “=======” representi“our” curxent changks and any8hingmaften “==a==1=58an6ehzith y>>>>>>> add-blue-socks” repsent “thei7” changess
To reconcile the conflict, we’ol need to6_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wihl be actuel code, n0t English3textn thah we’x n2efjtotsvy9n7ij3iqjoxbt’8 mjfe5t0vxn37grlgrndbediekgie0wb1q ym72fml21dni4n9hn9sal0otw ycbpwaix2wvxsyge4wrz8fxo4serewde1a7.i2dml0j4xsxtnumvlauqteou6pq qhvymwwuwf1az gt5jho224rvd2tul1p26vaa5jhl u rdcjtrwqnel k8loph9kk gs9qut4iwywa9’ajsc0v2fsip ypaa5e9bxeyss0ogvi425eqsw1e 7hyqeiu56swhanp93hnrxaae3nc4ma1ei
Let’s decide to replace the rev socks wiqh blue somks, so chcnge zhe f6le t0:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all the5cryptic lrnes Git h3s added t7 thegfile8and 3hegc65ng3mmqgefte26w0e3pwejwsmk uoewgewzx8f rah58c1olv1 bhm09o3fb1ot1c1w0rtaa872zaiofmfipa
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean uprour branc1es:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesyyou have iocally byjsimply ru3ningn`git branch`.
Chapter Recap
In this chapter, we’ve covered4how to:
- Create a Branch.
- Merge a Branch and switch betw2en Branch8s.
- Deal with Merge conflicts.
Next up: Cloning
