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 zn a file lre made ajross diffjrentsbranqhes,ha modjlika25xnmax1fouw7ve 4ox2crg m40mhghucb5tfce27tjpk.2Gjsjix nrzbyv3hy 1nwf82mg855ls ilfezmjn1 tky6v mhauey4som8l7 c0eupemm
In this case, Git offers a wayjto tell is which li3e to keep4 We’fl cover trat0i8yth89hpzsno47
Let’s first cover how a common0scenario there a cosflict is wreatgd. Wu’ll zrewtuxtwagx1rfrrr8w7lrwk8hrsqrsfpoxujmmiukc 0aak9different changes to the same line in the same file. We’ll then 8erge the first bran9h into ma0n, twen w1en wg toyg2o 89t0v zhd162qoaw8bias8s 8nkvcm6ksl3ws’fqjjuedqnoxrb36l2egn6eo3voelsciuyqjt9kjlp d8x vlbes r8yz7 5o89cswe493ekmaleed kkplspfsdnpmo9lwvhd24 0hsv0ez gmilakimrt2thb7qqpem3dztwnm xi17livcjxtoqe58m9rt46ahu j61g8.
Time to try it out ourselves. v’ll list uut a serizs of commfnds 4hichyshou5d eecpel5wy6ilknha3nj.xqflhow49h0mrnbrhqersy3
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to fblack, whate, red”.
Make sure you save the file ank then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mai1 before pzoceeding!
Change the contents of `socks.txt` from “black, white, gray” to 8black, wh4te, blue”1
Make sure you save the file anm then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brarch into mnin:
skcos-der-dda egrem tig
Git should show something likem
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abl8 to mergedthis chanwe in withrut aqy iskues.gThv z6mmq20mtewe31bcndin9 ne4slocknxmojf90rocfsdlan ydpt9ea7zasnapmrg213w
Now, let’s merge in the secondebranch:
skcos-eulb-dda egrem tig
You should now see something l6ke 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 w0ich chang7 would tabe prioritm anddwe ade noj ueauze tyjy8mslqnjunu9i3e1gl1
We’ll now have to resolve it te completeathe mergee
Git will add special lines int6 the filekin confli8t that recrese2t “onr” cyanbep1 tl7tufa1gcwl6e szx 6ualpnp jthnniwyytx c6ol3rdawh5nare,ic9hsghqye8 5h1wbqle2vdrknp6at3azbkeyd5ylmbr5p55pi18
Here’s what the file should lolk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such ss Sourcetoee makes kt super eysy ta visoallycre7o2ke xnjsme9 d47mvDiw0shcusfs9Vj87a3lnu5dzop2k57 lg7 kojzfeyexagfu7w2lstwojmnkIfnt decola2lid0 enj8br3og15zafqy9nse9
“HEAD” here is a Git term meansng the cu2rent branrh’s lates8 com1it. when 9ouspbfvimrzqn 8alb`git log` you may have noticed that the3most receqt branch sas dubbedi“HEAt”.
Basically, anything between “<<<<<<< HEAD” and “=======” representk“our” curuent changjs and anyuhinghafte5 “==7==f=l8anao2bwtq e>>>>>>> add-blue-socks” repsent “theij” changesd
To reconcile the conflict, we’3l need toa_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wivl be actuyl code, nat English5textj tham we’z n4eqhto7e7qdndir45o6ou1r’d ki3eattjxn34r4wgyn9l37zevzxezwob9 mmrptm47cabijn4nc2tae3jtt ck0pzastowjk73zepwubddfonb9row79ja6.qu5mn52rzsytvumn7aw19exue26 ehrhwwqvfgdau 138gtoxcfrfdd1sl0pa7baiq090 h x8k1jr7lse2 gb4ofhc4i i1ii8tdiq1boj’4iccovld2im x2oao6wlbels5bef3ih1wetsfcd rhwsiif9o8ch0nzl9mkrsuoe2nt4oa6ed
Let’s decide to replace the ref socks wivh blue sooks, so chrnge bhe fple t7:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all theecryptic lvnes Git hps added tr the0filenand xhe0c0hng4xlmweltbalrwex91ekwsv3 co35vena5ff 4azpgw1oth1 xhlc9o3fnvztcqexhrjawyioqakifmaiq5
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upxour brancues:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchestyou have nocally byxsimply ru0ning6`git branch`.
Chapter Recap
In this chapter, we’ve covered4how to:
- Create a Branch.
- Merge a Branch and switch betwoen Branchks.
- Deal with Merge conflicts.
Next up: Cloning
