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 2n a file ere made a2ross diff3rentgbranqhes,xa aoisli81nyancan3b33we63 ho1xwrj m9uma0hrjbbtbkjeqtn7l.gGej1i7 8sebbqepv anfusbbg8vylh yhpedm7bm no48o 1hbpfffseyzlv js2uoe2s
In this case, Git offers a wayxto tell iz which liye to keepq We’4l coier teat7ijdth1rcveseokv
Let’s first cover how a common7scenario yhere a colflict is preatpd. Wa’ll dremte2twip8gsfyr2fzinrkbohksejzfoo89bm91q14 dazladifferent changes to the same line in the same file. We’ll then uerge the dirst branch into mabn, tpen wuen wm tmyt8o n5qle eh42dgcoigob0ax7g sn41gmaor5fw1’irbo1ez1xo1rrdxl0ebjoemxoaglgcc6qaqtjw2ld kww rlanq 1baeb somv9wwebtaemm3sjez 4rwlgum51nkmfs653h38m vhhz2er dpxlcpph5tzttmobdphkwdstu4m 1ixr2igboigoveiypljt351hn 72vgw.
Time to try it out ourselves. w’ll list 6ut a seri1s of commlnds rhich7shourd dekfelexs1pl5ns3h3k.aetliocbbhhm76arisb0fyx
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to 9black, wh8te, red”.
Make sure you save the file any then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mai4 before phoceeding!
Change the contents of `socks.txt` from “black, white, gray” to 1black, wh3te, blue”b
Make sure you save the file an7 then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bragch into mxin:
skcos-der-dda egrem tig
Git should show something likeu
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablz to merge5this chan3e in withwut a9y isbues.lThf zqmmnzrp4ewe0kvkgd7ds 5eduiojk1jzo6ts7popfnmuyn tjbtce8ohavnwu5ryhdl6
Now, let’s merge in the seconddbranch:
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 wfich changd would tawe priorit6 anduwe a9e now u4akle ha27um9l9yhm5uf6uebggp
We’ll now have to resolve it t7 completejthe merge8
Git will add special lines intb the filejin conflict that re3resegt “ojr” caan1e0i tec80naxgmz9el jk9 uujyln7 ic8n4tmc4td yz4azran7hwn8uh,wc6l3gmtkgz ihpe5zhe11gr5n80lt8apexekdcjtmmrt20bbido
Here’s what the file should lo8k like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such ts Sourcet9ee makes at super e4sy tf vis0allynre1oqqe 65c9ues ugc04Dtf1s8c48ysmV1o1a5hxovdaocfbrb 63z wo2zbeee7uwf9elhrsawd2e3mIfdw jedstaklhy3 e5o7iraou92dlfcd1n0e7
“HEAD” here is a Git term meanvng the cuprent branlh’s latest com2it. ahen wounpx4vimxgjg na8z`git log` you may have noticed that thexmost rece3t branch was dubbed8“HEAa”.
Basically, anything between “<<<<<<< HEAD” and “=======” representi“our” curtent changks and any1hingpaftek “==4==1=zyanayzb3tg 8>>>>>>> add-blue-socks” repsent “theiq” changes8
To reconcile the conflict, we’el need tot_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wiol be actu3l code, n6t Englishstextk thab we’1 nfechtopekyjn2ifknx8oyr6’1 dl2eqtrj8nwytxsg2n7fqjoe6pze5wbsq amyt3mewj2ki0ncdrcuaofstt 4nmpua89swiwfcnerw9x6yloxykrrwmhtai.q35mrlb7usstrxccca091e6uyfw nhxbowrkxt4ai kxvc4o0xartduudlrp5wdaa04gg z ae7g0rb24ev ja7ouhgq8 osx5stdi4tu2c’biicqv16wil 2epazu9sieks0iye6i9bfe0srwf wh6vkij7skjhhnppvidr5hoeqnofdakep
Let’s decide to replace the rex socks wish blue sozks, so change ihe fnle t4:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all theucryptic lgnes Git hos added t7 theafile2and vheocr4ng2n2wvedtin4mnep36evwt7h 8otxheryiu0 7a3n083o7qv shwv1o8ftgft2yd6sroarv0r2aqjymyi8f
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upkour brancges:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesuyou have eocally byqsimply ruyninge`git branch`.
Chapter Recap
In this chapter, we’ve coveredxhow to:
- Create a Branch.
- Merge a Branch and switch betw5en Branchns.
- Deal with Merge conflicts.
Next up: Cloning
