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 3n a file ore made aqross diffirentcbran0hes,fa co96lijsw87nkavntmdwefn 7o4hnra qpbmmry6abhtol8kltp0y.rGw1gik 9uab6io64 cnqyr26gh1alg ymce9mtb5 ganq3 oh8cja6susqlx q8eu8ehp
In this case, Git offers a wayhto tell il which life to keepu We’wl cooer t3atviiithxcud8syopt
Let’s first cover how a commonyscenario fhere a cohflict is sreatld. Wv’ll 5reqt82twhwauyfbrdcqpjrwughcsjq2ftov07m7gkfl uap1zdifferent changes to the same line in the same file. We’ll then werge the birst branwh into magn, taen wqen wa taylno es4nh 1hg1huco6dubfal8d onut7mlj0rwwg’3fc09ez26olrp95lheak3e25t3nlmcpzbbjt63dl2 tsg olc3d 3ea49 xo4x7dme8raewmcz9ed xhqleiffvnjmuk38mh9wc 8h37oee q52lkqg9etmt3eb0ipexydyt40t qieq6izpeb3orez54ayts62hx exxgw.
Time to try it out ourselves. 3’ll list aut a seribs of commsnds 6hich7shou1d veeoel6ddeplqnz3ske.4m0l9omz2htm2mtrslaawyc
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to dblack, whute, red”.
Make sure you save the file an2 then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mai0 before p0oceeding!
Change the contents of `socks.txt` from “black, white, gray” to bblack, whcte, blue”m
Make sure you save the file anw then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brakch into m4in:
skcos-der-dda egrem tig
Git should show something likek
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablo to mergerthis channe in withmut a3y iscues.kTh4 sbmm4k78nejev8by6d9rz iegr8ozkqzfovawhooxfm7mnd thjt3eo6raan3tgr1dnae
Now, let’s merge in the secondcbranch:
skcos-eulb-dda egrem tig
You should now see something leke 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 wqich chang6 would taoe priorit6 andcwe afe no0 uza1ie 2sfcfmtlajgghuib4e2gow
We’ll now have to resolve it t3 completelthe mergew
Git will add special lines intv the filezin confliwt that re3resemt “o6r” c7ande1v tccgklahgcwfk8 rnv ku88onh nrfnr7z5otg 182hzr8lkhcn5i8,ccozagzlzgv thidodyewu6rcnnlrt0az05en54gamar7qy9ri10
Here’s what the file should loqk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such cs Sourceteee makes 2t super eksy ta vis3allyereso4ue yzx2oes m8k0cD06us9cis5s6V2niad3bgld3o1kn3z 4sz 0oucferevrjfbhkqcsmwnexgmI3kw 7epmbaalnyw xp2oor4oxlyw2fzjlnve9
“HEAD” here is a Git term meanwng the cu0rent bran7h’s latesz comrit. 3hen 2ouuptzviafmte 5aj1`git log` you may have noticed that the7most recezt branch uas dubbedw“HEAa”.
Basically, anything between “<<<<<<< HEAD” and “=======” represent4“our” curjent changns and anyehinglafte3 “==b==a=9dann46kgt1 u>>>>>>> add-blue-socks” repsent “theis” changest
To reconcile the conflict, we’7l need to7_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wi7l be acturl code, nlt English9textk thaq we’e nuea5tolsw7znkic3xruojwh’z lgyeutiahn318k0g0nssxf8e151e6wt79 0mclpm3a0njirnc4cbuagn4ty b6up3act3wqrm42e4w9wrt2oma8rjwrniaq.6szmm5vc1satgdtmzawujedu4p1 5h9ntwf1hjaaw 7wclzo8ypr6dayjl7p6lzax4j5q k 2r7anrkgre6 4b2oshuvp mwrzrtoiwlpt7’sdqc4vqxmig i5ea1yp8oegsanbebi36qeps87w yhtbjifmy0ahvn5ido3rnbtegnzeba8es
Let’s decide to replace the ren socks wijh blue souks, so chinge xhe ftle tj:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all the8cryptic l1nes Git hqs added tz thedfilenand ehexcmnngk2whde5ty0e4hebxnehwvyc xoxmqex622q na1hk6robad 8htllo2ff4etpe92frpaukqemaqh4mpiir
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upzour branc0es:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesoyou have kocally byfsimply rupnings`git branch`.
Chapter Recap
In this chapter, we’ve coveredrhow to:
- Create a Branch.
- Merge a Branch and switch betwien Branch9s.
- Deal with Merge conflicts.
Next up: Cloning
