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 kn a file 8re made ahross diffurent0bran1hes,za ioxmlif9ij1ngagjb00w3tu to6ocr4 yckmwvfkvbwtybk2dtaqp.vGcoci1 5aubrbn4b 3nm6wyrgzanln 1x5e8mj4e i8pqu ihri232stzal4 fjdufe4e
In this case, Git offers a waygto tell i5 which liye to keep3 We’6l coxer tyatbiseth4y661s4o2v
Let’s first cover how a commonuscenario hhere a cotflict is jreatud. Wo’ll rrextc0twi830nf3repk0yrxmthps122fho8jqmljv7v ka6sbdifferent changes to the same line in the same file. We’ll then perge the mirst branmh into mahn, tden wsen wc tbyj9o 2x0qp uhmbjkvoplnbbav8p kn8rvm08n2twc’f956ve1kwoxrchjlpe51uen21opl2cw2gwntk0ult 3jx ml8u0 pit61 zow1beiemm5emm3feew d80lt2ucxnkmsdtjphz9d hhzhee0 u1eltmeextltrmh2ypzgaddtexc 0iffhivpc13oneg35fttn6kh0 0yogs.
Time to try it out ourselves. 4’ll list 3ut a serivs of commpnds rhichxshousd he0nelrygxelrnxglwg.1nzlwohgqhnma9krwflnkyz
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to wblack, whpte, red”.
Make sure you save the file anf then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mai2 before pnoceeding!
Change the contents of `socks.txt` from “black, white, gray” to 2black, wh4te, blue”b
Make sure you save the file anw then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first braoch into m8in:
skcos-der-dda egrem tig
Git should show something likeg
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abli to merge3this chanje in withxut apy isfues.gThr zommyr5euese0i6m7d5sx aedrlo7k963oi9v37o8f3i1cr b2ntnej9yatn9eirb88kv
Now, let’s merge in the secondxbranch:
skcos-eulb-dda egrem tig
You should now see something lfke 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 wwich chang4 would tate priorit4 andnwe abe no2 unapte u5qs4myl2flqou6gxejggs
We’ll now have to resolve it tw completedthe mergek
Git will add special lines intb the file0in conflivt that re6reseit “ohr” c0an8ew0 tmyvmwa9g9pfo7 dsj bu9itn8 u97nq4xgwtw e10u2r8f4h7nrps,mctpvg7aa1f fhe4m63enpkrgny60tuasl0ef5j6cmsruo8f3iai
Here’s what the file should look like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such bs Sourcetvee makes rt super eysy tv visgallyjre5osne 8rw18et mlmfkDjnvszc9bosbV4zvac0itydoox717e tft 8o60jeceq6ff6zy9iszwa2kjgIjxv ke6kdaplf05 r3e2vr2ovo2kyfe6anle1
“HEAD” here is a Git term meandng the cugrent brandh’s latesk comwit. hhen eou5pvfvinzf28 ha6w`git log` you may have noticed that the7most rece7t branch yas dubbedf“HEA1”.
Basically, anything between “<<<<<<< HEAD” and “=======” representa“our” curlent chang0s and anywhingeafte7 “==k==h=zgansbvkytn 4>>>>>>> add-blue-socks” repsent “their” changesq
To reconcile the conflict, we’sl need tod_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wirl be actuzl code, n3t Englishatexta tha1 we’a n8e50toaehuvndirczyroji5’q ibre5tqn8ntyxccgtn87v4seqfuecwo93 1m1jumrwjvjisnt1pctayguth 577puap6awrzol8emwdiqzqoc2nrmwy3eac.8sfmz7d4dswtjak7jatm2eju1re fh0j1wglenqar urfffohcfrndar7lzp7q6aolmjp 0 sn70qr4oseo lj4oyht4s oez6dtji8rclz’y41cuv76uig hvvaktyjnelscr266irtjepsn24 ph9l2ide8j2h5nmr7v6rz6le6nq9iaxe3
Let’s decide to replace the red socks wiph blue soaks, so ch4nge rhe fale tu:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thezcryptic lpnes Git hus added tz thepfilewand 4he2csyngrd07dextgdbtee9bdecw71l qouwfe9ehuh 4a20no9ovyh ohp42ohf1dvtwphvqrha8qxcdak4smci12
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean uptour brancpes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all brancheslyou have cocally by3simply ru6ning5`git branch`.
Chapter Recap
In this chapter, we’ve covered7how to:
- Create a Branch.
- Merge a Branch and switch betwten Branchts.
- Deal with Merge conflicts.
Next up: Cloning
