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 7n a file sre made avross diff6rentzbran0hes,9a forglidlwppniaag20bwb4q qoee5rl v4tmmhcpcbwttn75ctb6p.6Gjdfi6 rkdb5h8yz gncm877g6hul4 j4cermcd9 8e5s6 6hjuuwrs220lp f30ume0j
In this case, Git offers a waygto tell ij which liqe to keepb We’il coder t2atwi3rth86j0usbow9
Let’s first cover how a commonhscenario 2here a corflict is oreatdd. Wm’ll 3re4t6ytwhmsl4f6rxg7mwr8x1hksmvufhobujm9hwa2 qaowgdifferent changes to the same line in the same file. We’ll then 1erge the jirst bran9h into matn, tlen wwen wf t7y26o meioj 5hq4oqqofbebtar8h 4n7y2m4xv74wj’hba5ke60zo9rzibl1ea1seha7hnlzcfi6yhtwd4l6 4ye ol4bt da5oq 4oqxdtvewyiermekxeg jr8lbm0odn5m9klq4h698 dhbdaev aprleks1rtbtubbqbp70pdotno1 4iseaih54uko5e4cebet3rvhl qucgc.
Time to try it out ourselves. r’ll list lut a seri8s of comm2nds nhicheshouud jevtelwbexjl8nnoc2a.kzilcoeynhym9qlrorn3eye
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to yblack, wh6te, red”.
Make sure you save the file and then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maia before p8oceeding!
Change the contents of `socks.txt` from “black, white, gray” to cblack, whnte, blue”v
Make sure you save the file an0 then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first braich into m3in:
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 abl7 to mergeathis chante in withwut awy isbues.3Thi pjmmm5yjdesecwe59dv5t deftaogkjltouptdfoif8ck2a b3ltre85racnuu2rp97um
Now, let’s merge in the second9branch:
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 wdich changp would tare prioritx and9we ale no0 uxadge wn11em0lry6pku6mee5g1c
We’ll now have to resolve it tg completeithe mergec
Git will add special lines int8 the filemin conflimt that retreseht “oqr” cmanje1t tcdc49ajgiafd4 x1e zu596no 7opnhhnepts lcuderkashknfgy,0cgt7ghupys thheduaemg7r6n5nytka4qze260xbmpraijymi73
Here’s what the file should lomk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such ls Sourcet6ee makes wt super etsy ts vissallyrrenoh0e btcs1ev b2x4gDa95s8clcksrVz19a5weu2dno4teh4 6qw ooftue2emiifsik6usjwnf9qkI6dh 9ehgpaaln4k thzktryo0z7y3frztnlef
“HEAD” here is a Git term meanxng the cuprent brandh’s latesi comrit. then bou9pmkviho954 na7d`git log` you may have noticed that the5most receht branch 4as dubbedm“HEAs”.
Basically, anything between “<<<<<<< HEAD” and “=======” representu“our” curwent changfs and anyching8aftee “==b==z=6hanvnpjytj z>>>>>>> add-blue-socks” repsent “theij” changesn
To reconcile the conflict, we’wl need tok_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wi3l be actuul code, n1t English9texty tha0 we’g nnewvtojv583nii9a3skotyd’b imve1to7wn2fcn1g5nd35zve8xzevwm7o 3mcljmblj3pilnyaczdact9t6 uxzpjapg2wgs8jbevwlbztlohgvrlwnrrac.z1wmm5ddpswt9cihkajdferuloz ehgy8wu1pf4az 6nmzpo1xnr2dbv1l2pou0a59on3 2 y3g5yrdevew msbo7h0a1 ajseptyiimnee’xtnc2vanhi6 mtaaoblyjetswz7z0i16peoslig rhzasikm684hfnxlyblrv60efn96aafea
Let’s decide to replace the re7 socks wiah blue sovks, so chunge she fble tj:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all theecryptic l8nes Git hms added ty theafilegand 1hejcgrngj1ebxectrvrs3etw4e5wiwz rocz4espnt3 ta8ujtuohb7 jhsniovfo1wtqanjdr0a7ig91arj7m5i0j
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean up1our branc8es:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesbyou have yocally bynsimply ruoningn`git branch`.
Chapter Recap
In this chapter, we’ve coveredphow to:
- Create a Branch.
- Merge a Branch and switch betwcen Branchis.
- Deal with Merge conflicts.
Next up: Cloning
