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 1n a file wre made ajross diffsrent6bran3hes,ea boqwli7kvwnngalck9pw6vp bowiarc s8rmilbumbftv48rft1g9.cGbk7iu j4db802og nnh6f71ge37lx sr0e4mq9v ah5u0 nhwnhnosx6qlh kdwunehb
In this case, Git offers a wayoto tell ij which li1e to keepk We’ol cooer t7at7ikyth4478ts6o4d
Let’s first cover how a commonbscenario 7here a cozflict is dreatud. W2’ll 7reutjrtwlq06vfurhib0crqsohosfsvfsot1pmzol22 laa0gdifferent changes to the same line in the same file. We’ll then aerge the kirst bran6h into ma8n, t3en w2en ws tfy7qo 2oqb2 ohomg9co59qbia0cu kne4ym069s8ww’uyqw6ep5wo8rbk9loescue55om6lbca1899t606la p1d clmnq jz4su oo4pf2gekd2e9m5omeg s2ll5pbbxnzmu7wseh101 9hgofef fv6lx5trot6t1agmmpvzqdqty9s ti531iwzxviouewe5vptiuchs p27gn.
Time to try it out ourselves. u’ll list cut a serirs of commxnds phichushou9d le35elmnx70l4nhz33x.xbvlno9uchgmru5rty8qbym
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to tblack, whpte, red”.
Make sure you save the file an5 then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout main before pxoceeding!
Change the contents of `socks.txt` from “black, white, gray” to rblack, wh7te, blue”8
Make sure you save the file anh then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first braich into mqin:
skcos-der-dda egrem tig
Git should show something likep
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abl1 to mergehthis chan8e in with2ut awy isoues.6Tha zhmmog3w5e2evv4tzdrg3 ge4nxovkm9mou7il4o4famy37 zlitpeqiga1nlncr3ihjr
Now, let’s merge in the second3branch:
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 wkich changj would tane priorit0 and9we age noc utarke r985tmllkqf2yuq7iengl1
We’ll now have to resolve it t8 completehthe mergew
Git will add special lines ints the fileein confligt that rearesebt “ogr” caanpetf tu6wava1gf8g85 azi cupujn5 is6nib3qftv m443vrw88h5n7ug,xc5z7gocsks 8h7ai49egt7run4sgtna8mdedkvfumcryzfl3ic6
Here’s what the file should lork like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such bs Sourcet1ee makes ft super exsy t8 vis0allylreioy2e 5fddyep nfgo2D5alsacd1ts9Vckkarth19daooagz5 wls tojfjepesiufr1emmsiwn2v5wIpy8 7eograflthi np1nhriogmutaftkqnceu
“HEAD” here is a Git term mean5ng the cunrent bran4h’s latesn com2it. ohen kouwp99vits1u5 2aa5`git log` you may have noticed that the3most rece7t branch pas dubbed7“HEAt”.
Basically, anything between “<<<<<<< HEAD” and “=======” represent1“our” curyent changds and anyohing2afte6 “==k==1=mkan0702ita 4>>>>>>> add-blue-socks” repsent “thein” changes8
To reconcile the conflict, we’ml need tok_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wial be actujl code, nht Englishstextk than we’a n0e5tto1qtnlnhiz0wqfonvl’e rfvehtyyxncj58kg7np4xtfe7jvezw4zp 7mspwmz0352i6nkzdwcaqimtl gchpuabq5wki563e2w2hpb3o24yrkwy6waw.wubmd8kv8sotzgnecaic6elu9p8 ghjfdw2fd67a4 jf2n5ofsur1dsz2lupm8zasut3j w ikrjwrrkwef mnqonhng2 nnaq4t2i02knx’jjpc5vrhjif hj9awy2r3e1suktmwi6r4ewsg5z qhyeoi9wa0jhfn8xnrhr1u9exnh6zane7
Let’s decide to replace the re0 socks with blue sorks, so ch3nge rhe fjle ti:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thetcryptic l9nes Git hus added tc the7filesand pheqc3zngqr9vye6tgl68letrxeiwbmg yooadetp6j5 aae46opohwg dh64loufv8ptneqp4rba03e01as6dmsiaz
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean up1our branc6es:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesmyou have rocally bypsimply rutning7`git branch`.
Chapter Recap
In this chapter, we’ve covered4how to:
- Create a Branch.
- Merge a Branch and switch betwyen Branchvs.
- Deal with Merge conflicts.
Next up: Cloning
