How do I finish the merge after resolving my merge conflicts?

文章推薦指數: 80 %
投票人數:10人

Teach ' git merge ' the --continue option which allows 'continuing' a merge by completing it. The traditional way of completing a merge after ... Home Public Questions Tags Users Companies Collectives ExploreCollectives Teams StackOverflowforTeams –Startcollaboratingandsharingorganizationalknowledge. CreateafreeTeam WhyTeams? Teams CreatefreeTeam Collectives™onStackOverflow Findcentralized,trustedcontentandcollaboratearoundthetechnologiesyouusemost. LearnmoreaboutCollectives Teams Q&Aforwork Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch. LearnmoreaboutTeams HowdoIfinishthemergeafterresolvingmymergeconflicts? AskQuestion Asked 12years,5monthsago Modified 5monthsago Viewed 475ktimes 373 63 I'vereadtheBasicBranchingandMergingsectionoftheGitCommunityBook. SoIfollowitandcreateonebranch:experimental. ThenI: switchtoexperimentalbranch(gitcheckoutexperimental) makeabunchofchanges commitit(gitcommit-a) switchtomasterbranch(gitcheckoutmaster) makesomechangesandcommitthere switchbacktoexperimental(gitcheckoutexperimental) mergemasterchangetoexperimental(gitmergemaster) therearesomeconflictsbutafterIresolvethem,Idid'gitaddmyfile' Andnowiamstuck,Ican'tmovebacktomaster whenIdo $gitcheckoutmaster error:Entry'res/layout/my_item.xml'wouldbeoverwrittenbymerge.Cannotmerge. andIdid: $gitrebase--abort Norebaseinprogress? andIdid: $gitaddres/layout/socialhub_list_item.xml $gitcheckoutmaster error:Entry'res/layout/my_item.xml'wouldbeoverwrittenbymerge.Cannotmerge. WhatcanIdosothatIcangobacktomymasterbranch? gitgit-merge Share Improvethisquestion Follow editedJun16,2017at10:00 VadimKotov 7,81688goldbadges4646silverbadges6161bronzebadges askedMar18,2010at23:43 michaelmichael 101k114114goldbadges239239silverbadges341341bronzebadges 5 2 AfterIfixtheconflict,performtheadd,andthenattempttoperformthecommitwithgitcommitgf2n.cpp-m"Handmergegf2n.cppduetoconflicts",itresultsinfatal:cannotdoapartialcommitduringamerge..Andofcourse,"Partialcommits"donotappeartobedocumentedordiscussedanywhereinthegitmanpages.PerformingagitmergeafterthefixresultsinPlease,commityourchangesbeforeyoucanmerge.Whatabrokenasstool... – jww Sep18,2016at3:51 2 gitcommitwithexplicitpathsisdocumentedinthemanpageintheDESCRIPTION"as"3.bylistingfilesasargumentstothecommitcommand,inwhichcasethecommitwillignorechangesstagedintheindex,andinsteadrecordthecurrentcontentofthelistedfiles(whichmustalreadybeknowntoGit);"andalsounderthe'--only'option.I'mprettysurethemergemessagewaswrittenbysomeonewhoassumedyou'dreadhowthecommitcommandworks,andcouldrecognizethemeaningoftheword"partial"inthatdescription,ifnotalreadythenatleastagainandmorecarefully.@jww – jthill Sep18,2016at5:08 1 So,whydoesthatcasestudymeritcarefulreadingforcomprehension,then,whilethemanpagesdon't?@jww – jthill Sep18,2016at5:46 1 Well,usinggitclearlyrequiresbetterreadingcomprehensionthanyou'repreparedtoacquire.I'mperhapsevenmoreunsurethat'safaultingitthanyouaresureitis. – jthill Sep18,2016at6:02 3 WithGit2.12(Q12017),youwillsoonsimplydoagitmerge--continue.Seemyanswerbelow – VonC Dec28,2016at20:56 Addacomment  |  12Answers 12 Sortedby: Resettodefault Highestscore(default) Trending(recentvotescountmore) Datemodified(newestfirst) Datecreated(oldestfirst) 341 Whenthereisaconflictduringamerge,youhavetofinishthemergecommitmanually.Itsoundslikeyou'vedonethefirsttwosteps,toeditthefilesthatconflictedandthenrungitaddonthemtomarkthemasresolved.Finally,youneedtoactuallycommitthemergewithgitcommit.Atthatpointyouwillbeabletoswitchbranchesagain. QuickTip:Youcanusegitcommit-am"yourcommitmessage"toperformaddandcommitoperationsontrackedfilessimultaneously.(Credit:@vaheeds) Share Improvethisanswer Follow editedMar19,2021at12:47 KitangaNday 3,10422goldbadges1616silverbadges2828bronzebadges answeredMar18,2010at23:52 JimmyJimmy 33.9k1313goldbadges7878silverbadges9696bronzebadges 7 Ifyouuse"gitgui&"todothecommit-youmaynotrealizeyourbranchstateisnolonger"merging".Followingupwitha"gitstatus"ishelpfultoensureyourbranchstatusiscorrect. – TonyAshworth Aug25,2015at19:52 9 Trygitcommit-am"yourcommitmessage"toperformaddandcommitsimultaneously. – vaheeds Jul24,2017at8:30 4 gitcommitdoeswork.Andit'sbesttouseittogetthedefaultmergecommitmessagepopulatedforyou.Iavoid`gitcommit-am"sinceitwilloverridethemessage – Arijoon Aug16,2017at9:27 1 Trygitpush. – alper Feb13,2018at8:34 Igotthissituationinbelowscenario->ImergedXbranchwithYbranch.ThenirealisedididsomethingwronginbranchY,soifixedthatandthenI"amend"mychangesinYbranch.Becauseofamendgitdidn'tcreatenewcommit.SowhenImergedXbranchwithupdatedYbranch,Itgaveconflict.BTWthanksforthisanswer. – doga Mar13,2018at17:24  |  Show2morecomments 256 HowdoIfinishthemergeafterresolvingmymergeconflicts? WithGit2.12(Q12017),youwillhavethemorenaturalcommand: gitmerge--continue Andifyoudon'twanttoeditthemessagewhencontinuing/resumingthemerge: gitmerge--continue--no-edit If--no-editdoesnotwork,asakselireportedinthecomments,youcando: #Linux GIT_EDITOR=truegitmerge--continue #Windows cmd/V/C"set"GIT_EDITOR=true"&&gitmerge--continue" Youcandefineanaliasforthosecommands. Seecommitc7d227d(15Dec2016)byJeffKing(peff). Seecommit042e290,commitc261a87,commit367ff69(14Dec2016)byChrisPackham(cpackham). (MergedbyJunioCHamano--gitster--incommit05f6e1b,27Dec2016) See2.12releasenotes. merge:add'--continue'optionasasynonymfor'gitcommit' Teach'gitmerge'the--continueoptionwhichallows'continuing'a mergebycompletingit. Thetraditionalwayofcompletingamergeafterresolvingconflictsistouse'gitcommit'. Nowwithcommandslike'gitrebase'and'gitcherry-pick'havinga'--continue'optionaddingsuchanoptionto'gitmerge'presentsaconsistentUI. Share Improvethisanswer Follow editedMar9at9:08 answeredDec28,2016at20:55 VonCVonC 1.1m488488goldbadges41054105silverbadges48394839bronzebadges 8 Iwasgettingreadypostacommentabouthowthiswasrecentlyaddedin2.12inQ12017,butthenIrereadthefirstlineofyouranswer.Nowondertheoptionwasn'tfoundformeonversion2.10! – cjsimon Mar11,2017at0:21 1 Itriedgitmerge--continueandGitBashwasn'tabletorecognizethatasacommand.Butwhatworkedwasgitcommit-m"Commitmessage" – Mimi May17,2017at18:18 2 @MimiOK,butareyouusingaGit2.12ormore? – VonC May17,2017at18:38 @VonCyouarecorrect,IamusinganolderversionofGit! – Mimi May19,2017at0:28 1 Itisconvenient,butmergedoesn'thave--no-editparameterforcaseswhenIdon'tneededitingcommitmessage.gitcommit--no-editworksjustfine – KirillLappo Sep1,2021at19:38  |  Show3morecomments 28 Incaseyouevergetstuckduringamerge/rebaseyoucanalways gitreset--hard torestoreyourworkingtothestateofthelastcommit.Thiswillloseyourchangesfromtheworkingtreesoifyouhadlocalmodificationsbeforethemergetheywillbegoneafterthis—whichiswhyit’sadvisabletonotstartamergewhenyouhavelocalmodifications.:) Share Improvethisanswer Follow answeredMar20,2010at11:33 BombeBombe 78.9k2020goldbadges120120silverbadges125125bronzebadges 2 25 obligatorywarning:gitreset--hardthrowsawayuncommittedchanges – GeoffreyHale Feb15,2016at19:27 13 Whynotjustgitmerge--abort,whichhasnoriskofloosinganything? – AlexanderGeorge May8,2019at1:17 Addacomment  |  13 Justgitcommitit. Optionallygitabortit: Iranintoamergeconflict.HowcanIabortthemerge? Tomakelifeeasierwithonmergesinstallkdiff3andconfigureitasamergetool.Instructions:http://doodkin.com/2016/05/29/git-merge-easy-github-this-branch-has-conflicts-that-must-be-resolved-use-the-command-line/ Thatpagecontainsthisvideo:https://www.youtube.com/watch?v=Cc4xPp7Iuzo Share Improvethisanswer Follow editedNov1,2017at16:01 VadimKotov 7,81688goldbadges4646silverbadges6161bronzebadges answeredSep23,2016at18:53 ShimonDoodkinShimonDoodkin 4,0743131silverbadges3737bronzebadges Addacomment  |  12 Thenextstepsafterresolvingtheconflictsmanuallyare:- gitadd. gitstatus(thiswillshowyouwhichcommandsarenecessarytocontinueautomaticmergeprocedure) [commandgitsuggests,e.g.gitmerge--continue,gitcherry-pick--continue,gitrebase--continue] Share Improvethisanswer Follow answeredFeb19,2016at14:00 TimidfriendlyTimidfriendly 3,17444goldbadges2626silverbadges3636bronzebadges 8 17 Thereisnogitmerge--continue – HolaSoyEduFelizNavidad Jun15,2016at14:15 1 @HolaSoyEduFelizNavidadThisisincorrect.Ziegitoutputbelowafterconflict:-error:Failedtomergeinthechanges.Patchfailedat0001ADD:_typetostyleguideThecopyofthepatchthatfailedisfoundin:.git/rebase-apply/patchWhenyouhaveresolvedthisproblem,run"gitrebase--continue".Ifyouprefertoskipthispatch,run"gitrebase--skip"instead.Tocheckouttheoriginalbranchandstoprebasing,run"gitrebase--abort". – Timidfriendly Jun20,2016at8:09 5 Thereisrebase--continue,notmerge--continue – HolaSoyEduFelizNavidad Jun20,2016at9:30 gitmerge--continue,whichiswhatIamtryingtodo,resultsinerror:unknownoption'continue'.I'mfairycertainyouransweriswrongsincethegit-mergemanpagedoesnotlistit.WhatversionofGitareyouusing?Iamusinggitversion1.8.5.2(AppleGit-48).IalsotriedwithMacPortsgitversion2.9.3. – jww Sep18,2016at3:33 1 Withgit2.10forasimplemergethecommandisplainoldgitcommit – ChrisCharabaruk Dec8,2016at20:40  |  Show3morecomments 12 +50 WheneverYoumergetwobranchesusingcommandgitmergebranchabranchb,Therearetwopossibilities: Onebranch(letssaybrancha)canbereachedbytheotherbranch(letssaybranchb)byfollowingitscommitshistory.Inthiscasegitsimplyfast-forwardtheheadtopointtotherecentbranch(inthiscasebranchb). 2.Butifthetwobrancheshavedivergedatsomeolderpointthengitcreatesanewsnapshotandaddanewcommitthatpointstoit.Soincase thereisnoconflictbetweenthebranchesyouaremerging,gitsmoothlycreatesanewcommit. Rungitlogtoseethecommitafteryouhavemergedtwonon-conflictingbranches. Nowcomingbacktotheinterestingcasewhentherearemergeconflictsbetweenthemergingbranches.Iquotethisfromthepagehttps://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging Githasn’tautomaticallycreatedanewmergecommit.Ithaspausedtheprocesswhileyouresolvetheconflict.Ifyouwanttoseewhichfilesareunmergedatanypointafteramergeconflict,youcanrungitstatus Soincasetherearemergeconflicts,youneedtoresolvetheconflictthenaddthechangesyouhavemadetothestagingareausinggitaddfilenameandthencommitthechangesbyusingthecommandgitcommitwhichwaspausedbygitbecauseoftheconflict.Ihopethisexplainsyourquery.Alsodovisitthelinkaboveforadetailedunderstanding.Incaseofanyquerypleasecommentbelow,I'llbehappytohelp. Share Improvethisanswer Follow editedJun20,2019at13:05 answeredSep23,2016at18:43 SouravPremSouravPrem 9931212silverbadges2424bronzebadges Addacomment  |  3 Stepstoresolveconflict: First'checkout'toyourbranchinwhichyouwanttomergefromtheother branch(BRANCH_NAME_TO_BE_MERGED) "gitcheckout"MAIN_BRANCH" Thenmergeitwith"MAIN_BRANCH"byusingcommand: "gitmergeorigin/BRANCH_NAME_TO_BE_MERGED" Auto-mergingsrc/file1.py CONFLICT(content):Mergeconflictinsrc/file1.py Auto-mergingsrc/services/docker/filexyz.py Auto-mergingsrc/cache.py Auto-mergingsrc/props.py CONFLICT(content):Mergeconflictinsrc/props.py Auto-mergingsrc/app.py CONFLICT(content):Mergeconflictinsrc/app.py Auto-mergingfile3 CONFLICT(content):Mergeconflictinfile3 Automaticmergefailed;fixconflictsandthencommittheresult. Nowyoucanseeitisshowing"CONFLICT(content)",tothosefilewhichishaving"CONFLICT",seeyourcodeandresolvethem run"gitstatus"=>Itwillshowyouwhatarethefilesthatyouneedtoadd(whichyouhaveresolved): Unmergedpaths: (use"gitadd..."tomarkresolution) bothmodified:file3 bothmodified:src/app.py bothmodified:src/props.py bothmodified:src/utils/file1.py Onceyouhaveresolvedallconflict,addeachfileonebyonebyusingbelowgitcommand gitaddfile3 gitaddsrc/app.py gitaddsrc/props.py gitaddsrc/utils/file1.py "gitcommit" (addsomemessagewhenyouaregoingtocommit,ifnotthenitwillopenviorvimeditorwhereyouneedtopress"esc:q!"thenpress"enter") runagain"gitstatus" OnbranchMAIN_BRANCH Yourbranchisaheadof'origin/MAIN_BRANCH'by10commits. (use"gitpush"topublishyourlocalcommits) 7."gitpush" Share Improvethisanswer Follow editedAug19,2020at11:38 answeredAug19,2020at2:29 RohitMauryaRohitMaurya 15411goldbadge11silverbadge1010bronzebadges 1 Ifyoudon'tgetanyconflictthenafterstep2,directlypushtogitbyusingstep7 – RohitMaurya Dec7,2020at13:12 Addacomment  |  2 ThefirstthingIwanttomakeclearisthatbranchnamesarejustanaliastoaspecificcommit.acommitiswhatgitworksoff,whenyoupull,pushmergeandsoforth.Eachcommithasauniqueid. Whenyoudo$gitmerge,whatisactuallyhappeningisgittriestofastforwardyourcurrentbranchtotothecommitthereferencedbranchison(inotherwordsbothbranchnamespointtothesamecommit.)Thisscenarioistheeasiestforgittodeal,sincethere'snonewcommit.Thinkofmasterjumpingontothelilipadyourbranchischillingon.It'spossibletosetthe--no-ffflag,inwhichcasegitwillcreateanewcommitregardlessofwhethertherewereanycodeconflicts. Inasituationwheretherearecodeconflictsbetweenthetwobranchesyouaretryingtomerge(usuallytwobrancheswhosecommithistoryshareacommoncommitinthepast),thefastforwardwon'twork.gitmaystillbeabletoautomaticallymergethefiles,solongasthesamelinewasn'tchangedbybothbranchesinaconflictingfile.inthiscase,gitwillmergetheconflictingfilesforyouANDautomaticallycommitthem.Youcanpreviewhowgitdidbydoing$gitdiff--cached.Oryoucanpassthe--no-commitflagtothemergecommand,whichwillleavemodifiedfilesinyourindexyou'llneedtoaddandcommit.Butyoucan$gitdiffthesefilestoreviewwhatthemergewillchange. Thethirdscenarioiswhenthereareconflictsgitcan'tautomaticallyresolve.Inthiscaseyou'llneedtomanuallymergethem.Inmyopinionthisiseasiesttodowithamergetook,likearaxismergeorp4merge(free).Eitherway,youhavetodoeachfileonebyone.Ifthemergeeverseemstobestuck,use$gitmerge--continue,tonudgeitalong.Gitshouldtellyouifitcan'tcontinue,andifsowhynot.Ifyoufeelyoulousedupthemergeatsomepoint,youcando$gitmerge--abort,andanymergingwillundoandyoucanstartover.Whenyou'redone,eachfileyoumergedwillbeamodifiedfilethatneedstobeaddedandcommitted.Youcanverifywherethefilesarewith$gitstatus.Ifyouhaven'tcommittedthemergedfilesyet.Youneedtodothattocompletethemerge.Youhavetocompletethemergeorabortthemergebeforeyoucanswitchbranches. Share Improvethisanswer Follow editedSep25,2016at1:32 answeredSep25,2016at1:09 HarryRobbinsHarryRobbins 52444silverbadges1515bronzebadges Addacomment  |  2 Amergeconflictoccurswhentwobranchesyou'retryingtomergebothchangedthesamepartofthesamefile.Youcangeneratealistofconflictswithgitstatus. Whentheconflictedlineisencountered,Gitwilleditthecontentoftheaffectedfileswithvisualindicatorsthatmarkbothsidesoftheconflictingcontent. <<<<<<>>>>>>merging_branch Whenyoufixyourconflictedfilesandyouarereadytomerge,allyouhavetodoisrungitaddandgitcommittogeneratethemergecommit.Oncethecommitwasmade,gitpushthechangestothebranch. Referencearticle:Gitmerge. Share Improvethisanswer Follow answeredMay22,2018at12:06 NeshaZoricNeshaZoric 5,6583838silverbadges3434bronzebadges Addacomment  |  2 Afterallfileshavebeenadded,thenextstepisa"gitcommit". "gitstatus"willsuggestwhattodo:filesyettoaddarelistedatthebottom,andoncetheyarealldone,itwillsuggestacommitatthetop,whereitexplainsthemergestatusofthecurrentbranch. Share Improvethisanswer Follow answeredJun19,2018at12:44 hobgoblinhobgoblin 6744bronzebadges Addacomment  |  2 Itmaybelate.ItisHappenbecauseyourgitHEADisnotupdated. thiscommendwouldsolvethatgitresetHEAD. Share Improvethisanswer Follow answeredApr24,2019at6:02 MortezaMalekabadiMortezaMalekabadi 16111silverbadge1414bronzebadges Addacomment  |  0 Anotheroptionalso,Itriedstashandworkedfineformewithoutanycommit Afteryouresolveallconflicts, ->gitstash ->gitstashapplystash@{0} workedfine,youcanswitchtoanotherbranchalsoafterthis. Share Improvethisanswer Follow answeredJul30,2021at18:53 DanDan 2122bronzebadges Addacomment  |  YourAnswer ThanksforcontributingananswertoStackOverflow!Pleasebesuretoanswerthequestion.Providedetailsandshareyourresearch!Butavoid…Askingforhelp,clarification,orrespondingtootheranswers.Makingstatementsbasedonopinion;backthemupwithreferencesorpersonalexperience.Tolearnmore,seeourtipsonwritinggreatanswers. Draftsaved Draftdiscarded Signuporlogin SignupusingGoogle SignupusingFacebook SignupusingEmailandPassword Submit Postasaguest Name Email Required,butnevershown PostYourAnswer Discard Byclicking“PostYourAnswer”,youagreetoourtermsofservice,privacypolicyandcookiepolicy Nottheansweryou'relookingfor?Browseotherquestionstaggedgitgit-mergeoraskyourownquestion. TheOverflowBlog Ahistoryofopen-sourcelicensingfromalawyerwhohelpedblazethetrail... Thelasttechnicalinterviewyou’llevertake FeaturedonMeta PlannedmaintenancescheduledforTuesday,August23,2022at00:00-03:00AM... PleasewelcomeValuedAssociate#1301-Emerson StagingGroundWorkflow:QuestionLifecycle AnnouncingDesignAccessibilityUpdatesonSO Shouldweburninatethe[maintenance]tag? Linked 3037 Iranintoamergeconflict.HowdoIabortthemerge? 1472 Youhavenotconcludedyourmerge(MERGE_HEADexists) 6 GitFlowReleaseFinish-Permissiondenied 0 Gitpullismissingchanges Related 5230 HowdoIresolvemergeconflictsinaGitrepository? 1680 HowcanIselectivelymergeorpickchangesfromanotherbranchinGit? 1026 Gitworkflowandrebasevsmergequestions 24643 HowdoIundothemostrecentlocalcommitsinGit? 8841 HowdoIforce"gitpull"tooverwritelocalfiles? 1953 MakethecurrentGitbranchamasterbranch 2528 HowdoIsafelymergeaGitbranchintomaster? 1707 HowcanIreconciledetachedHEADwithmaster/origin? 1690 CanIdeleteagitcommitbutkeepthechanges? HotNetworkQuestions "Buyassets,notliabilities":Howisitpossibletobuyaliability? Finitegroupswithintegralcharactertable WhyarebeansIsoakmyselfalwayssmallerthancanned? StandbytravelonKoreanAirviaICN CanauniversityforceaJ1exchangestudenttopurchasetheirhealthinsuranceplan? SwitchingICforanalog/compositesignal Howwasthistextureeffectachieved? WhyexactlyisNewton’sSecondLawvalidonlyinnon-acceleratingframes? Howtoexplaindifferencesinmutualintelligibility? Lefthandfingerexercisegivingmassivetension CanadecompilerdeducethestringsIwroteinsolidity? IsitlegaltofixaniPhonewithanonoriginalbatteryinCalifornia? Arethereanyprobabilisticmodelsforthelikelihoodoffindingarogueplanetclosertousthanproximacentauri? HowcanIfindmagicitemsintendedforaspecificclassonD&DBeyond? UpperboundofP[X



請為這篇文章評分?