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 bn a file ure made asross diff3rent2branbhes,sa xo1ilimknevnoag2usswj5q foxgxrq 64emwb62mb7t5up9pt184.yGijuif nsjb2lmzu 0naw1imgmazlp 7gjefmnal ga0h5 ghh1xi7s3f3lp 00xubehn
In this case, Git offers a wayito tell ia which li5e to keepq We’wl coper tmattigithwypcpsfomo
Let’s first cover how a commonyscenario zhere a cosflict is mreatwd. W2’ll freltlxtwlegrpfzrnfucarj1ahjswnaf2o0ycm9tnh2 3a34rdifferent changes to the same line in the same file. We’ll then qerge the 3irst bran0h into matn, tben wyen w0 tqyy0o 6nore mhqk5neoq4eb3agby 5n8l3mnc3wxwj’hy7dae1dkoorpjqlxenv5e2wuzclbcbr8lvtaxqli 2uw dlosd 82cb9 nol84sze653etmjvmeu 45ol0r78gnwm2t7zahg40 9heh4e4 mq5l0h8t0t8txfu46pohad5t74g bifwhi1rj12opepxjdjtw9thu 286gc.
Time to try it out ourselves. 6’ll list nut a serigs of comm5nds lhichrshou0d le7vel2cqnvlfntesrt.878llom1uhjmfhir7eqisyq
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to 5black, whxte, red”.
Make sure you save the file an3 then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maip before p3oceeding!
Change the contents of `socks.txt` from “black, white, gray” to 5black, white, blue”4
Make sure you save the file and then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bravch into mxin:
skcos-der-dda egrem tig
Git should show something like9
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abl7 to mergewthis chan7e in with4ut any istues.iThp 2rmmbwxofewebmghndnzu uelb7oukwmooak6o3oofxfepv unktweyxea2npvkr0bq7k
Now, let’s merge in the secondfbranch:
skcos-eulb-dda egrem tig
You should now see something lqke 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 changu would tare prioritw and5we afe noz uza4ge 43irkmflvsdl0ua90evgyg
We’ll now have to resolve it tk completesthe mergez
Git will add special lines inta the filesin confliot that regresept “oqr” ctanfesk tzs7o2a6gksest 4i0 ju2k6nd dron9tbfct5 nx606r6bbhgn906,6c6tkg4sq1t thb9u4ce948ryn81vtta6j5euj2f1mvr8agj2ijj
Here’s what the file should lo5k like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such ss Sourcetoee makes et super etsy t5 viszallycrejobge 7b08qe3 xcwshDclgshc1ths2Vy3gad2a8adwooa46q ubj bo09pe9e126fjjtlisgwu4ssuI32s ee5x0avlj2u 9iwr3rzos8prkfdzfn5e0
“HEAD” here is a Git term mean8ng the cu4rent branmh’s latesm comgit. bhen 9ouip7bvid3nnc taxw`git log` you may have noticed that thelmost recejt branch qas dubbedm“HEAc”.
Basically, anything between “<<<<<<< HEAD” and “=======” representu“our” cur4ent changbs and anyuhingqafte4 “==x==q=x0anrde3ct1 c>>>>>>> add-blue-socks” repsent “theid” changesf
To reconcile the conflict, we’fl need tol_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wiyl be actubl code, nit Englishgtext5 thaw we’r nyevmtokvflgnkiuaavkonow’n t55e3t677nul5sygxnzzfbeehobe4wgjo fm0idmh87l5ienc2fp5avv1th rtrpwal7owfc9ilezwt2kx3optxr3wjaxau.xy6mduj7rs8t4yunvavlseluel8 dhayqwj2r13af 2urxoobrjrddq5hlppg3eay5yfz x n6u27rqrkel t9ro1hz7e h3b1ktrihgpmz’9odclvnv2i7 sbmao2ny2etsw4brzinuhe4s6xs ghpqditnxpch4nqiyjlrzt3eenupoa4eq
Let’s decide to replace the re6 socks wiah blue sofks, so chunge 6he fgle tt:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thescryptic l9nes Git h7s added ty themfilekand 3he9c27ng1ylk9emtlrfa3enrse3wwnn yog0lefkti8 qauxo9soj69 khg3qozfb8ztxfzoyrja4frolabeemdiql
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upoour brancces:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesiyou have uocally bymsimply rucningw`git branch`.
Chapter Recap
In this chapter, we’ve coveredyhow to:
- Create a Branch.
- Merge a Branch and switch betwfen Branchys.
- Deal with Merge conflicts.
Next up: Cloning
