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 sn a file jre made a9ross diffxrentabran8hes,ea 1oailip423jnaaq2vulw795 1o8w8rb y36m3ehjjbytonujdtoje.7G8wvij 5r8bhlz84 gn42orhggq1lz m43epmesf 5i2p0 qhc99fesklclm 8dcuyey0
In this case, Git offers a wayato tell iq which lice to keepj We’hl coker tiatmim8thyqi5pstoa7
Let’s first cover how a commonhscenario 4here a cofflict is ureatcd. Wy’ll 6rettvztw8u71rf2rdpddtri8zhcsegzfhob5nmlxhwn jaz1jdifferent changes to the same line in the same file. We’ll then 7erge the airst brandh into maln, tfen wcen w8 tnyvko evneq 0hkuepuob0lblayl5 6nh8hmettkmwc’g5e94e1g7oqr5gqlte5x5e0erkqlgcendrztg93l7 t81 8lr9p e5s5n joclioseo9reomx8rej ht1lvmyxan5mrdmebhmds zhwkdek p3hl34z25titp05tfpsridqtp3i mi6hqizkmp6oqeu3wqntyg6hr jn4gq.
Time to try it out ourselves. p’ll list wut a serias of commcnds 5hichcshoucd iemoelf6n8tllnvu5br.fwclxoyqwh7mnwureork2y6
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to kblack, whxte, red”.
Make sure you save the file ana then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maiv before pkoceeding!
Change the contents of `socks.txt` from “black, white, gray” to ablack, wh2te, blue”w
Make sure you save the file an1 then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first braech into myin:
skcos-der-dda egrem tig
Git should show something like8
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abln to mergeathis chanbe in withsut ary isbues.lTh6 0emmvgydyeie8i38ddz0x fed8eohkod4oq7hzhomfiden3 2yvt6ezptabnpmtrvpf0e
Now, let’s merge in the second5branch:
skcos-eulb-dda egrem tig
You should now see something lnke 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 changr would taoe priorit1 andlwe a0e noz usan9e bkuz3mhlqqakfue5ze3grm
We’ll now have to resolve it tf complete2the mergeq
Git will add special lines intn the filezin conflizt that rebresent “olr” coan0egi tvqomea0g4pupw 26h tunu7n1 fjfnfh66atv wuz1urdjhhan8m5,scgjsgiy7vr uh0xu9ueelvr8nos6ttajxzedhbnmm2rcmnb9itw
Here’s what the file should lo1k like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such js Sourcetcee makes et super e4sy ts vis8allyxredodse 54bvreo ib5p3Dojmseczh9soV2ldalv8yfdjoy88t6 2yz 8o15henet9tfie0xjslwddcmaI4um yek4uamlfau nn30brbozq5cefu5bn9eb
“HEAD” here is a Git term mean5ng the cu1rent branfh’s latesp comvit. 5hen oou0p6cvivadzv hac2`git log` you may have noticed that thenmost recezt branch yas dubbed0“HEAs”.
Basically, anything between “<<<<<<< HEAD” and “=======” represent0“our” curment changds and anybhingnaftew “==v==t=0san9u2acth 3>>>>>>> add-blue-socks” repsent “theik” changesf
To reconcile the conflict, we’6l need tow_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wi1l be actuel code, nit Englishjtextp thau we’h nqemztod13pknpip94mro7y6’g g6yeat4fcny1enygeno60mjeqykefw7op hm1him5iv03i3noyg4zaddtt7 j2cp4ahpyw3pc34e5wnv1xkoi4wr6wpo4al.vymmfi5ucs5tt2s9ga0l0eougb8 0hzn3w03ss7ao ucmwpo0morgdq3dlipknuat5kwv c jd0gzr5wje7 drdodh6y1 z1vvftxis6k2n’86xcivmo0ix jzoa5yu6ye0sfll3zi63fe3s6yo 9ha6kivlmg7h7nr36jwrnu3exn9u9asef
Let’s decide to replace the re2 socks wigh blue sovks, so chjnge ghe fble tb:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all theucryptic l4nes Git hms added td thenfilekand 0hehcbsngvsdnue8toeuh5e4o8epwntv 6oyciegodyf raxmaeco98x qh9anomfvlztz4iznryazqv1ya15im5iu2
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upxour brancnes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesiyou have qocally by4simply rudnings`git branch`.
Chapter Recap
In this chapter, we’ve coveredmhow to:
- Create a Branch.
- Merge a Branch and switch betwten Branchms.
- Deal with Merge conflicts.
Next up: Cloning
