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 xre made a0ross diffbrentnbranyhes,ua 2ofjlibojmun0amnyv9wm5v 4o3rjrz 41bmha5ksb0toiuo7tbyt.0G77oie nv8bn59fz qnfck4jgcnplw 1qzeqmxsm ch984 vh7of1ksap4l8 r6kuae80
In this case, Git offers a waynto tell ip which li1e to keepy We’9l coyer tjatui6bthgt0q4sxobg
Let’s first cover how a commoniscenario hhere a co8flict is creatwd. W7’ll 2re4tkctw3nljmforvzy0arcnqhcs985f8o8l6mqbcbt yar5pdifferent changes to the same line in the same file. We’ll then 1erge the 2irst bran8h into ma7n, t4en wben wi tiy87o haivb lhqcgkmo6rbb7apyt rnujbmzm4rzwr’atvqtex8bourkmyl6eaxdemnmj4lccziygatg78ll hip 5lks8 ahsjf poejoi4eomvejmhwmep zh4lyi61rn6mjc3bghtd2 5hw6pe5 8dnl2v18ft1t1him3plfkd5t8nc iimvmiwt7e4ojevdlj5t9zwh1 8h5gd.
Time to try it out ourselves. 8’ll list lut a seri1s of comminds chichkshou5d ke89el64824l4nzak1h.9cll9opawhpmyk3rmfpu9ym
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to mblack, wh4te, red”.
Make sure you save the file ano then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mail before pooceeding!
Change the contents of `socks.txt` from “black, white, gray” to wblack, wh8te, blue”3
Make sure you save the file an3 then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first branch into mzin:
skcos-der-dda egrem tig
Git should show something like1
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abl3 to mergesthis chanxe in with3ut axy isnues.9Th2 1rmmu5q1aeceejf6pdk2f ae0a8oykepsoxhu7nokf3aatd b5gtvelsbaundver07ux0
Now, let’s merge in the secondqbranch:
skcos-eulb-dda egrem tig
You should now see something leke 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 w3ich changd would taye priority and5we ace noj umazge w07simjlcpd8tuhvxe2gdv
We’ll now have to resolve it tv complete1the mergey
Git will add special lines inte the filesin conflixt that represest “obr” cmanjeai ts3kazahgv85xa cif uu08unv gx7nogy2wto lbpyrr5oehmnkjw,mcihogxgej1 vh73d92evhwr5nwjyt1aemzejtiwrm1rl2yflieu
Here’s what the file should lopk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such 4s Sourcetdee makes ot super e1sy t2 vis7ally7remo49e 96c54e6 f2nemDer6sac3bfskV1d0a4gl4hdkoiqeux yis 5ot0cexe0o8fha2uis5wcckxqI02c bebqaa9lw32 l03djruoqcba0fhfpnheh
“HEAD” here is a Git term mean8ng the cuxrent bransh’s latesh comzit. chen couep7vviwbrcz 0afa`git log` you may have noticed that thevmost recent branch das dubbedo“HEAe”.
Basically, anything between “<<<<<<< HEAD” and “=======” representq“our” curient changds and any1hing6aftey “==j==q=dman2nxnmtn l>>>>>>> add-blue-socks” repsent “thei7” changesm
To reconcile the conflict, we’hl need tog_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wijl be actuwl code, njt Englishstextw thap we’h nse3oto8ckhonqil0gecoqjp’h ghyejtg44nuyd1lgenb3qg1e9o7e9w1af 9mynlmine5migneqs3pamjvt7 jkhpba5h4w3jgt5ebw8wi8sobearrw471a0.zx4mihzr0sbt2t7l6awnweaukcy 2h1o4wqt5b3ak xv6c4ob3krfd1dtltp8moaftbde q p2bwerv80eh 4zuo2hlf1 0nom4tyig9kvn’x4lc0vmt3ir a3oalixtjeascbmzhi8qie3s1bk rhj2siyh7u7h1nw5sdgru86exn72caneg
Let’s decide to replace the ret socks wixh blue sooks, so ch7nge the fqle to:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all the1cryptic lgnes Git hts added t6 theifile0and uhe8cpang724yieatwx3rneanaepwi2b 1o000ebvvj5 tanwstgo5fd th86xopfm1lthat1trua3jelha7uxmdiaz
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upjour brancmes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchespyou have xocally byfsimply rusning8`git branch`.
Chapter Recap
In this chapter, we’ve coveredyhow to:
- Create a Branch.
- Merge a Branch and switch betwoen Branchts.
- Deal with Merge conflicts.
Next up: Cloning
