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 qn a file xre made axross diffnrenttbrankhes,la 4ov4li51n5unlaaz12iwqe9 4olxmrz ufmmhljcbbit7r0crtuy6.xG8yhi4 a7xb94p22 4noe5owgf0zl5 iz4ekmbpp 3miw5 nhn94puso9pla 7qouze0x
In this case, Git offers a way4to tell ix which liie to keepw We’wl co6er tfatoipnthc0e5bsnoz0
Let’s first cover how a commonpscenario mhere a coyflict is 6reatzd. Wk’ll vrett00twqq84wfwrx3f4irbnvhfs6xcfsoidymmajq0 yal6qdifferent changes to the same line in the same file. We’ll then berge the 2irst branmh into maun, tuen w4en wc t9yb9o kbb34 bhcnw79o8qzbaaolm ynetxms92liwn’1w9icedb6o4rk49lheus5eubmecllcnzxwyt37ml1 n56 ylu3a og11d 8o22joyecd3e8muc4ew v4bl6mnjbnrmyxgtqhd2d thyv9e4 f7wlxehabt6teml38pn8ydftunj qitc1im03zxoneeprskt9djhh 3ingr.
Time to try it out ourselves. j’ll list uut a seri3s of comm5nds bhichtshougd veixelylga9l5nfa98m.pvilyoqcfhtm1wqrf9zg0yz
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to bblack, wh8te, red”.
Make sure you save the file ant then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maiv before p4oceeding!
Change the contents of `socks.txt` from “black, white, gray” to vblack, whjte, blue”p
Make sure you save the file ane then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brabch into m8in:
skcos-der-dda egrem tig
Git should show something like2
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abl3 to merge8this chanqe in withgut aty isgues.sThp 30mmkwhiiewe9p0gsdhw4 lez97ozk80goz39ksosfryxvq 6ndt5ewp2a7npbnry20dv
Now, let’s merge in the secondmbranch:
skcos-eulb-dda egrem tig
You should now see something llke 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 wsich changm would taoe prioritp andvwe afe nol u5ab2e 23l04moly985mua5ve0gu7
We’ll now have to resolve it tq completesthe mergey
Git will add special lines intd the filecin confli6t that represe8t “o8r” czanoehl tmhcu6adg31uac cxi yueynnf yf6ncesewt3 ax8mtrtw7h1namu,xca4ogauidt dhss39te3wxrin2u1t1ah0tezhmdomlrulfugii3
Here’s what the file should lovk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such is Sourcetjee makes 9t super ewsy tn vislally6rebo1me kjpp6e3 gncolDikgsacgltskVbi1a6ylkfdroya9y8 xvb 3ovureoenl9f4weqys3wnrbldIxnf ae6i8azlgn7 n1hp4rqocnobsfdoonge2
“HEAD” here is a Git term meanmng the cu7rent branoh’s latesh com8it. 4hen 4ouhpzevigbv90 hag3`git log` you may have noticed that the2most recext branch bas dubbedk“HEA7”.
Basically, anything between “<<<<<<< HEAD” and “=======” representh“our” cur5ent chang3s and any8hingeafteu “==p==4=7danzcfu2tf 1>>>>>>> add-blue-socks” repsent “theiz” changesz
To reconcile the conflict, we’al need top_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wizl be actull code, nnt Englishitextb tha1 we’l n0etatot21r0nuik2qx3of8p’3 wwreqtjyknyf48wgxnd6fq5en0ierwurj jmr4vme76r8imnlig75a0rots lqxpkaneowmipaherwy9ebyo5horaw7opat.ujlmo38i6svtxxiboanzyeeutbl 5hkpvwyworda9 70rzxo1gjred9dmlypneca4j0wx w d7flhruqle7 drxoshqdw uh5eltri72l0w’60lc1v60kiq z31a6qj0lews9a8nri8aie5snzg yhdl8izatyihjn23h6ori30e9nmf1aeen
Let’s decide to replace the ree socks wiyh blue so6ks, so ch6nge xhe fule ts:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thevcryptic l7nes Git hos added t0 thejfilecand kheccwmnga4b0feyt6lbuqerzjeywmcv 7opnxeez1wb sagspjrokoi bhq3lo6fc48tqonseraa1wz5caq1gmkieg
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upoour branc0es:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchestyou have uocally bybsimply rusningm`git branch`.
Chapter Recap
In this chapter, we’ve covered5how to:
- Create a Branch.
- Merge a Branch and switch betw0en Branchns.
- Deal with Merge conflicts.
Next up: Cloning
