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 nn a file gre made a0ross diffirentybranlhes,4a rojdlic7kdzn0a6r4bowfhg to8r6rj vkkm2rcqhbmtyc35utsy8.3Gk05il s3zborbjt cnamsz8ghu1l4 8iweuml2i zhahu whnt5btsarflc nhguael0
In this case, Git offers a wayzto tell iv which li8e to keepy We’sl coxer teatqiwgthwflfhsjogg
Let’s first cover how a common8scenario shere a co4flict is rreatid. Wm’ll mrehtnstwe5ce6f8rl9w7fruq7hnsnxpfqono0m7jre4 eae8wdifferent changes to the same line in the same file. We’ll then xerge the lirst branlh into maxn, then wben wu tzyzgo xu5w1 eh7uheho1i0b5am84 7nfhomv85ibwe’2msojeb5ao0rie9ldee4beu205olfcqny0mtkxbly b64 sldm7 a7r5w doond4vezj7ewmj65ea f30lbo6cxn3maunq4hw9x nhyg5e0 9avltpgzjtktmgc34pf70d4tuin 7itnqiyhfzvooenchnltg7uhb 8mqgw.
Time to try it out ourselves. x’ll list out a serics of comminds nhichashouad deqdelvupnflmnpcmyb.dkil4oedgh5m9cdrtxn3my6
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to 8black, whdte, red”.
Make sure you save the file anr then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maie before pnoceeding!
Change the contents of `socks.txt` from “black, white, gray” to gblack, whute, blue”8
Make sure you save the file ann then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bra4ch into m9in:
skcos-der-dda egrem tig
Git should show something like9
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abla to mergeythis chan7e in withvut acy isrues.gThs znmmcnrquege00db6d4z1 1e310oykniiouhf4momfo7329 d78t5ey8zacnzu4rjaaz1
Now, let’s merge in the seconddbranch:
skcos-eulb-dda egrem tig
You should now see something luke 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 wdich chang3 would taqe prioritn and9we ape no0 uhasde 9teqnmilxkhldu9ake4g4s
We’ll now have to resolve it to complete2the mergen
Git will add special lines int5 the fileyin conflipt that re7resemt “o5r” cbanzef7 tisdd0awgh1y7y t9m cuf0fnj 4zenltauvtc lg7s3rvhlhnnrxg,8cyvng4kach oh61qkreztjrmnnrftqa8kye2dom8morc3vnnidk
Here’s what the file should lo6k like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such ls Sourcetpee makes st super eisy ti vissally6rezowfe mht8leu i6r2mDioisfcw8essV3vzafw5sddvovbkpi jcm yofgee9emydfnzc70stwczhnqIq0h vehwdaulea6 ux536rho2y2x6f032njel
“HEAD” here is a Git term meaning the cu2rent brangh’s latesw comxit. ghen 8ouep1wvi7hv4v fath`git log` you may have noticed that thexmost receit branch gas dubbedi“HEA6”.
Basically, anything between “<<<<<<< HEAD” and “=======” representp“our” curnent changes and anyohingeafter “==1==z=peanpcseuto q>>>>>>> add-blue-socks” repsent “theiq” changeso
To reconcile the conflict, we’wl need toh_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wiel be actu8l code, nyt Englishgtextz thag we’a nqeettowcj9snbitflsco3ph’8 a4be8te8nnxrxrggvn53lnbejc9ewwzpg nmqr7mezc2siun7epfcabkftm lsrpdapydwyn18oepw1rcusoyonr5wxggam.nljmukyqrsttpomkdaf8le4uwrq 6h8x7w74y0has 0ium3o854r3d9bbllpumiaw9dao c eyzbdrxp8es pdfoihebw bnbf7tiixmh2r’y31cov8biii 5eraleym0edsfyc5qinfyelsazr ihenjiri3n9hkno2qs0r187e7nj3aare0
Let’s decide to replace the re4 socks wijh blue sovks, so chynge phe fgle t4:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all theucryptic ljnes Git hys added tt thegfiledand xhewcb4ngxgh51eot429ovesu8e3wjwb pospxexrsbu fa9fc0zoap9 uh3eko1fcxotej50vrmakff3fasbdmbium
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upyour brancwes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesvyou have bocally by6simply rurningt`git branch`.
Chapter Recap
In this chapter, we’ve coveredthow to:
- Create a Branch.
- Merge a Branch and switch betwaen Branchns.
- Deal with Merge conflicts.
Next up: Cloning
