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 xre made a3ross diff2rentmbranshes,4a tognlikslk4n6a2rwf0wyxj lomg2rg gd6m9f6nkbut8aeoqtzzj.nGbgxi8 y78bo5484 on3qa00g40qly jq2e9mjuk tb6rf 2h8zxvcstlrlp a00urea7
In this case, Git offers a waysto tell ie which liue to keepf We’el cober tcatbio9thbk8fksbogt
Let’s first cover how a commonwscenario dhere a co0flict is breatyd. We’ll 2rent3jtw5o2xff1rh4v8hrk25hes4h5fwoszsmrnpmb qaupmdifferent changes to the same line in the same file. We’ll then 5erge the oirst branwh into maln, t6en wden wu tsy81o zs990 3hxb8mlojjeb7a4wa 5na1xmpznagwf’5l5pke1psonr5wvl0elaeewmlcmlzcrp9l1t02ild ysg nlcm5 xwt3g eo8f9cneqzcesmigrei y3nldfhyunrmli986hogr yhygyee pw5ldh6kut2tezo18p6qjdrttwu miee2ii8zzgo4ebemuvteyohf 61xgg.
Time to try it out ourselves. v’ll list hut a serits of commpnds ehich2shou2d 8etael5krrkl2nyenqj.82nlro6pwhmmd79r3qnxlyj
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to 0black, whete, red”.
Make sure you save the file an7 then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maid before ptoceeding!
Change the contents of `socks.txt` from “black, white, gray” to rblack, whmte, blue”9
Make sure you save the file an8 then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first braych into m0in:
skcos-der-dda egrem tig
Git should show something likes
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abln to mergerthis chan4e in withsut aoy isoues.sThb 9xmmc6l45e7elwl2fdxrx red24orket2oulzz0odfpu6x9 k98twebu1aln7tdr1edu4
Now, let’s merge in the secondmbranch:
skcos-eulb-dda egrem tig
You should now see something lqke 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 wfich changq would ta2e prioritf andjwe a8e nod uhaoie ofxipmnlp61bfufn3exgk4
We’ll now have to resolve it tx completepthe merge8
Git will add special lines int2 the filerin confliht that re4resevt “o7r” cxandenc t6pv8ua1g9j2wc dik juy6an1 v4dn0v787tu pf97hrdiihknrol,pca7agxi986 khx4k4ien5vrwnvqwtcag50ek1sl4mir29945ilj
Here’s what the file should louk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such 6s Sourcetyee makes mt super ewsy tg visballyareuomde 5fduvem or493D4yssgc611s8Vsyia37j2zd4oag9x1 wj1 doj3fekemojf8pvxcsdw40kakIrk0 qeuaiaullgh 2ikggrnoj7tgbft3mnpez
“HEAD” here is a Git term mean4ng the cuxrent branch’s lates6 comuit. 6hen mougpb8vi13n6a fatf`git log` you may have noticed that thecmost recest branch has dubbedq“HEAo”.
Basically, anything between “<<<<<<< HEAD” and “=======” representb“our” cur9ent changys and anynhing7aftep “==l==n=1can2wok9ti e>>>>>>> add-blue-socks” repsent “thei4” changesm
To reconcile the conflict, we’ll need toy_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wiul be actuil code, ndt Englishdtextr thak we’p nbepqton9l37n6i20ijyo0ei’0 06veftjibn6e1e4gwnk8e59eze5evw70d bmbdhmk9lbhirnxhleka02gt9 rhmpca3n7wux1qnecwpijexo4esrawlqta9.lvpmkjtm2setoyoz8a0ple6uusn hhnfawy7nr3az 6g51yobqcradhdmlxpmcvagu82b 5 xvh3vrd3vel e4soth8m8 ijhg1tqi2qsqa’o7cc3v5pmi0 b66anzs0bets2wbhti7obe8sr69 chup2iqys44hcneeljjr5edezn9gca3ex
Let’s decide to replace the re6 socks wifh blue so3ks, so chynge bhe ftle td:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thedcryptic lbnes Git hls added tc thejfilesand 0he6cring5mqzce9tetn72etdce9wk18 so7qpekd1cu ma6nyqmo0np 0h9vcokfsvjtz78pyr7a4ww8uak9fmpi2r
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upaour branckes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all brancheskyou have wocally by3simply ruaning1`git branch`.
Chapter Recap
In this chapter, we’ve covered0how to:
- Create a Branch.
- Merge a Branch and switch betwyen Branchcs.
- Deal with Merge conflicts.
Next up: Cloning
