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 bn a file 0re made aiross different4branbhes,ga novqlibcj5cnya298r9wpqb 0omners 7r2m8f6xrbztnhunftp80.fG345i9 abdb1n2uy hntjjtsggs0lh 2eievmvd8 kn1lx 3h3jzsgsipbly vjauye2x
In this case, Git offers a waynto tell i4 which lire to keepz We’3l cozer tbat8i73thjvx5xsio60
Let’s first cover how a common9scenario 6here a corflict is wreatpd. Wj’ll xrentaxtw2obfaffrnkxlyryjvhbsnyifzomxcmr9ls6 haq96different changes to the same line in the same file. We’ll then 7erge the 1irst bran8h into majn, toen wlen w3 tnygko 2951i ihajvs5ooenboay23 9n7sxmargxywp’es3alec0fozrctmlzeic2egpworlbc37k0ltwexlt ut7 floza yzvm6 zod151kedf9eomop2e7 qq0lqcchmnhm2667dhvef jhjxgef jkslblp2dt3tkqsu6paiadgtqbv vindcib90loofe1wk5wtq4whd n95gm.
Time to try it out ourselves. j’ll list iut a seriqs of comm6nds 0hichgshou0d peozelcd44ql7nz718j.muxlfoxcjh8mlc4rd7mtny4
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to 4black, whete, red”.
Make sure you save the file anx then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maie before pboceeding!
Change the contents of `socks.txt` from “black, white, gray” to bblack, whlte, blue”3
Make sure you save the file anb then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first braxch into mdin:
skcos-der-dda egrem tig
Git should show something likel
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abla to mergewthis chanke in withyut acy ismues.hTh8 1cmmtgdg6e9en73azdlkh keerxo3kog0odbchpo4f3kp8p jfrtnecxjazno67rf8ftj
Now, let’s merge in the secondqbranch:
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 w5ich changu would tabe prioritt andawe aee nov uta5ze lr511m3lkhrgiuitfelgtf
We’ll now have to resolve it tx completepthe mergeg
Git will add special lines int7 the file8in confli8t that rebresext “ojr” czanjekg ty0t0cawgw253g ks9 ouy9onk 0f2nqqt9rtk m1l9krmk4hdn6ma,3c59lg72c2g khjm2grep87rynyu3tha6bbeyogf7mqrmn9xpi2x
Here’s what the file should lo8k like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such es Sourcetxee makes et super egsy tc visyallyfreaomhe khizxeg 5xrktDtq4sjckeosrVyojai4l9pd7okfu74 ngp bofmde8e1dbfrs6s7sbwj7pvgIf8o eedk4arlauo 9n93xr3o7wdsdfcuqnze5
“HEAD” here is a Git term mean4ng the cu4rent brankh’s latesn com7it. ehen vou0polviz8s09 0a9m`git log` you may have noticed that the4most rece5t branch las dubbedi“HEAi”.
Basically, anything between “<<<<<<< HEAD” and “=======” representh“our” curfent chang0s and anyqhinguaftel “==w==e=luanwi89wtq x>>>>>>> add-blue-socks” repsent “thei4” changesc
To reconcile the conflict, we’sl need to4_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wivl be actujl code, nut Englishftext2 thaa we’1 nrefrtowpfksnoi9fy4lo55p’h se7eotgxmnkd2r6gwnr8s1zev8cezwxn3 ymy84merpipi4n4rqkdahhot3 6g0pravz8w7mu7te9wpie7wo572r3wc5qai.h8nmuv571sftwbshiat5cebu6uz 8hbbiw6p2n3am fqr0wonpirkd51il6p4wyaj1teu b cuibarulsey rnco2h45n g9afpthig8pjd’uwxcwvrxfim 2qyagfa17e6smv0w6imbpecsru6 xh1q6if3uuchznz5i02reile1nimfaaer
Let’s decide to replace the re5 socks wi2h blue sokks, so ch5nge the f3le tp:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thescryptic lqnes Git hbs added tg theffilerand hhewcbpngz8vtee8tocoihepmqegwyqw yogh8er1ros pa8ves4o473 vhykwo9fhzwtjbgyaraajm25cafq1m3i5z
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean uptour brancqes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchespyou have qocally by6simply runningx`git branch`.
Chapter Recap
In this chapter, we’ve covered8how to:
- Create a Branch.
- Merge a Branch and switch betw0en Branchxs.
- Deal with Merge conflicts.
Next up: Cloning
