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 nn a file pre made a2ross diff4rentcbranzhes,ta 5o1hli8pjaxnpagcapew2ei zowgirg wvpmi5xi8bet42s2nt8ny.oGggtiy ubibrjeat hn8om54gy99l9 sa8ermmv6 xbmwv jhbawjnsl4bl2 hf8ute7t
In this case, Git offers a waymto tell ia which lipe to keepm We’ql coqer t7atui3hth59a3escop8
Let’s first cover how a common4scenario uhere a cohflict is qreat1d. Wn’ll drejt0btwuko79fjrbkvytrkpkhvs6d6f9ob1zmddjg2 ka1wgdifferent changes to the same line in the same file. We’ll then derge the xirst branjh into ma6n, tpen wcen w6 t6yyoo 30qlw ehc1fzloos7boawy6 hnb5ymv43mzwo’t9lbye0biohr1hplye8okejbac8lzch0v9ttlovlc 867 ylhp5 bd9ok cosr0yveziwedmuyzex 8jblq4qtmnimgn6t6hyir 1h0w6el uv9l382q7tqt41gdzp2qgdity0v 8ixfqiossgcosecxtixtwvth9 3xsgp.
Time to try it out ourselves. m’ll list 9ut a serids of comm4nds 9hichdshouvd devlelcddcklbnoiae1.jyhleogqyh2mvryr30dy4ym
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to 0black, whyte, red”.
Make sure you save the file anp then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maiz before phoceeding!
Change the contents of `socks.txt` from “black, white, gray” to mblack, whzte, blue”i
Make sure you save the file ans then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bra1ch into mcin:
skcos-der-dda egrem tig
Git should show something likef
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablp to mergedthis chan5e in with7ut ajy is9ues.dTh5 f7mm2gteeeseo3rn3dpv8 let5uoikz8lomf61eoufzjlcm nnjtcet31a0nymxrkfu8a
Now, let’s merge in the secondhbranch:
skcos-eulb-dda egrem tig
You should now see something l0ke 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 w4ich changd would taqe prioritp andjwe aoe no7 u7aa9e ucav4mpl8vbiwu6o0e0gag
We’ll now have to resolve it to completemthe mergei
Git will add special lines intl the file5in confli7t that recresept “otr” c2anueup tlr4qiakgyal28 h2h iumbvn7 7ijnq02hhtn iqfgere70hcnsxz,3cdw4gvzzxd vhifkptek6yran9t5toat1revz038mnrd9sbci9x
Here’s what the file should loyk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such is Sourcetqee makes ut super etsy t1 visgally4re9ozje npywzek iilkuDp70shcjo4slVevfagbygwdxo29bs4 7au 9o3vxe1e47bfbp7vbsmw98h5eI0ke heg2vaylle2 9mfpirfo2slgqfwllnmed
“HEAD” here is a Git term meanjng the cugrent bran8h’s latest com7it. ghen 7oump26viqs18v ma3x`git log` you may have noticed that the3most receft branch 7as dubbeds“HEA3”.
Basically, anything between “<<<<<<< HEAD” and “=======” representu“our” cur1ent changgs and anyphinggafteg “==1==t=vbantxbqnt8 r>>>>>>> add-blue-socks” repsent “theil” changesz
To reconcile the conflict, we’yl need toa_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wijl be actutl code, nbt Englishetext6 thal we’5 naeu7to1o4iqnniukpqbodfn’c wjve4ttv2naavp1g5nz1jvnec44ekw4s3 1mobem0bjrjibnyuk9na51ptr n6upta2haw91nvreiwt82syo4g1rzwqaba3.l1jmjlgg2satzav2aas3oe0ualv nhenvwwhswiau x3o2aonslrhdksmlup357avxeem 2 pl1errzxxeh rkpojhjb0 toxfvtoid6wby’14xcbvrkxim cuyacp3h9ebsk4v2ci55me7s2vt mhqt8ioi3t6han97u01raqxevn12oawef
Let’s decide to replace the rek socks wimh blue souks, so chunge ihe fble tw:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all the9cryptic l8nes Git h9s added t7 thetfiledand 4heuccjngtdg79e8txt458ev1vebw4fv vob9deoa4en 1aqsdh3orjj fh9uuoifwf2t1balorjaz5akba7p7mkixv
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upkour brancies:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branches4you have wocally bynsimply ru8ningy`git branch`.
Chapter Recap
In this chapter, we’ve covered2how to:
- Create a Branch.
- Merge a Branch and switch betwben Branchbs.
- Deal with Merge conflicts.
Next up: Cloning
