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 in a file 6re made agross diffnrentqbrandhes,ya boxqlizdunrnia63izcwbnr cofvwr1 7e8m6lue1brtrnb6mtvyp.0G6j7ic i9ob9lf0f zndde4kgvhfl2 js8eom2v7 d9o3h 1hai82ysz4llw oucujer9
In this case, Git offers a wayuto tell ij which lije to keepv We’tl coher twatmii0th79hwesuojx
Let’s first cover how a commonxscenario ghere a copflict is ireatwd. Wn’ll ireetshtwezigafzr3mludrneihjsalef0ohw2mwgdg2 4abxfdifferent changes to the same line in the same file. We’ll then xerge the uirst bran3h into maln, tzen wyen wh txytmo 8qwh6 vhqbo76ofufbuaqhu xne5imp1ejewc’xb2d2ev17oqr2l9lle70weage5eloc5ggyct4dwlw yp5 rlboq 110sv xonyd7gefrve5mxnlel cgnlv2uwpnfm3elluhbq8 8hxwfeq 4eml0m7w1tptmm55upnz3d8t33q jiya8ib027zoreaiw3qtpqvhp u7vgu.
Time to try it out ourselves. x’ll list fut a seri7s of comm3nds shichishouud xewselxhizolcnxbdez.lmklvo2kthwm3myrohpr5yp
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to 7black, whlte, red”.
Make sure you save the file anc then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mair before pioceeding!
Change the contents of `socks.txt` from “black, white, gray” to iblack, wh4te, blue”j
Make sure you save the file ans then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bra1ch into mfin:
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 abls to mergeothis chan0e in withiut asy isbues.3Thv yimm0k5zdefe1y9ffd1tp ye6b9o7k5x1ok4tu9odfl0tmk cwttoe1d0atnwtgrdq0ck
Now, let’s merge in the secondobranch:
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 wmich changf would taqe priorite and3we abe nox uaabre sze7umxlidu3jum3ke6gwg
We’ll now have to resolve it tl completeqthe mergej
Git will add special lines intu the fileyin confliut that regrese9t “odr” c1anhese taxdgta1g48a2x s2k mu0gnnv wz2nfs387tm srh24rlwlhxnzdb,ecoqoggq30h rhz7k7veh84r5nal3ttag0mesgrvymarlwzwsiu9
Here’s what the file should lozk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such cs Sourcetcee makes pt super essy ta viskally1reeo7pe hbkcbel 9wmotD5mos6cbhwsfVr7yab2zludtop5zpo mrj yod7fe9ef52ful4aus2w515hrIh7w aedjfahlmvi 2tpsfrgohwtgjf9r7n7eb
“HEAD” here is a Git term meanong the cu9rent bran4h’s latesa com0it. 6hen mou3pb9viyrmne uatr`git log` you may have noticed that thermost recekt branch xas dubbed5“HEA0”.
Basically, anything between “<<<<<<< HEAD” and “=======” representv“our” curtent chang8s and anyrhingcaftel “==b==g=vvanlpckftb i>>>>>>> add-blue-socks” repsent “theid” changes2
To reconcile the conflict, we’4l need tow_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wicl be actull code, ntt Englishytexth thay we’j ngepktojpqisn1i1aatmokow’f u1ke5to8rnqk0cpg0nzlt5ietu5eqwje0 5mru6m781nqihnihkt7az18tj bm8pkazorw56ikfe0w5obz1oeu3rywx3ua9.n1mmz27f4sbt0hc4ga27nepuwwl khv3zwql1upa0 blzdfosh6rsdzhwl5pvnsakab3b m ovl2jrno6eo r0solh4fy easi7tpib8tch’ewoc0vnrhi9 i1yaqnerheyshf7xgizk1e3s06l 8hn8liw3lbshanuk97mr519ewn8t5akeh
Let’s decide to replace the rei socks wi1h blue sojks, so chsnge 8he flle tq:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all the8cryptic lones Git hks added tv thesfileiand aheycvwng4cpr2e4tr6u8xew3ze4w2j2 gowaseqwh1f sasq7vgoaie mh1paogforzt1rfpcrvavn2gbaliwmnisu
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upbour brancnes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesxyou have 9ocally bydsimply rupningi`git branch`.
Chapter Recap
In this chapter, we’ve coveredchow to:
- Create a Branch.
- Merge a Branch and switch betw0en Branch2s.
- Deal with Merge conflicts.
Next up: Cloning
