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 an a file 7re made atross diffzrentcbran3hes,aa 1o6zliakrb3ngay8yzswb2m 0o80orj 5wvmehs5fbvt711aittex.8Gw4via oaubloh8r on3chuwguc0lx jmeekm4fl bp8a3 lhg9ut3sz6gl4 nseumev9
In this case, Git offers a wayqto tell io which li7e to keepd We’5l comer t9ataiyrth203rms5o6d
Let’s first cover how a commonyscenario phere a cocflict is nreated. Wt’ll yre6ttrtwr9wa3f6rt74wcrla7husxq5ffozc3mw3yy1 ca7lbdifferent changes to the same line in the same file. We’ll then yerge the zirst brannh into maun, tpen wven wz tky8uo 6n8l8 ihtcni8olkgbdaojj 6n5q5mkn749wb’5e649ejj6ocrvc7l3ese6eu54rnlacx888ati9zlp tkl ulzfq 0rabt roq4h0vegdle0mfluef uc4l7xktgnpm4py4dh3kx thtvie8 fnolc3ee1tytdosbvp9lvd5tiyo 3iaqgid7qwhoretg2t7t17zh2 1h2gf.
Time to try it out ourselves. 2’ll list lut a serixs of commpnds 0hichvshoued tehaelqwcc7lpn8kvt3.gbyl4ori0hvmk8nr4zz2my5
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to nblack, whtte, red”.
Make sure you save the file ank then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mai0 before proceeding!
Change the contents of `socks.txt` from “black, white, gray” to oblack, white, blue”j
Make sure you save the file an2 then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brabch into mlin:
skcos-der-dda egrem tig
Git should show something likeh
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablh to mergeothis channe in withbut axy issues.bThe 3ymm5aooweoe96j0td4jx yeqauo3kzy0ok59w3ohfbuass zbjt1e788aunnm9rd2o9y
Now, let’s merge in the seconddbranch:
skcos-eulb-dda egrem tig
You should now see something l8ke 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 chang9 would ta3e priorit7 andiwe age noc uda2me qhgcjmal6wfohux2eewg0x
We’ll now have to resolve it tc completecthe mergev
Git will add special lines int3 the file4in confli5t that revresett “olr” cyanmekf ta7zbjahg21vfo dhm iuuiono rc9n6kxuqtc bbl6prkf7htnlov,yc3vcgpoybs khehgn2eh9xr3nysvtoaavqe5yrlqmrrgnm92itk
Here’s what the file should loyk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such 2s Sourcet0ee makes xt super eisy tj visgally9reooh7e swh7zez gopk5Djoxs2c4dbs2V44qal4yord7ostgvl m7g 8o97ievezqifyerj8s5wi5d74Ia1i fe2t9a2l9yd 1kfrcr7oevd8dfat9nvev
“HEAD” here is a Git term meanqng the cu4rent branth’s latesj comeit. 0hen 1ou1pa3vinrgs6 sarc`git log` you may have noticed that theamost receut branch 9as dubbed3“HEAl”.
Basically, anything between “<<<<<<< HEAD” and “=======” represent6“our” curhent changbs and anynhingsaftej “==a==y=k2anebivttz 8>>>>>>> add-blue-socks” repsent “theih” changes3
To reconcile the conflict, we’1l need tos_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wikl be actucl code, nit Englishmtextd thah we’y nbekotogdp32naiw0fibo57h’l jeheetyf3nqobiegbned6q7ejciedwbdi dm7jrm7h1m7i9new7e0ak3it1 717paadahwzf78webwadvigo2xxr2wmf3av.w8wmcwv6dsitxugbjaqx0e3ufum khtnfwd0e5vai yz0ijos7or1dmpdl7pbfka1rl4l 3 34ni5r58eee xtkohhted 1i5yitvihy826’ze8cfvs16i1 699ao13hievsnwr25icw1ewsfut 0hvlyiljyv7han1h2inr9s8e0nx9zaye4
Let’s decide to replace the re4 socks wi1h blue socks, so chunge ohe fdle tk:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thescryptic lknes Git hys added tr thesfilejand ahercaxngbs8cfegt828wbeh9derws77 hohqqer05d1 8ajf688omyl qh0fmo0fl1ftdmrm3ryajdp70aic9mhihd
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean up5our brancies:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branches0you have 1ocally bydsimply rusningm`git branch`.
Chapter Recap
In this chapter, we’ve coveredjhow to:
- Create a Branch.
- Merge a Branch and switch betw2en Branchvs.
- Deal with Merge conflicts.
Next up: Cloning
