How do I finish the merge after resolving my merge conflicts?
文章推薦指數: 80 %
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
延伸文章資訊
- 1How to Resolve Merge Conflicts in Git? | Simplilearn [Updated]
Learn the basics of Git merge conflicts and the advanced operations of Git, resolving a Git merge...
- 27. 使用rebase 合併【教學1 使用分支】 | 連猴子都能懂的Git ...
To check out the original branch and stop rebasing run "git rebase --abort". 和merge 時的操作相同,修改在myf...
- 3git-merge Documentation - Git
Use git commit or git merge --continue to seal the deal. The latter command checks whether there ...
- 4合併發生衝突了,怎麼辦? - 為你自己學Git | 高見龍
git status On branch cat You have unmerged paths. (fix conflicts and run "git commit") (use "git ...
- 5Git指令git rebase - iT 邦幫忙
如果用之前提過的merge方式去合併(在master上用指令git merge iss2) ... git rebase --continue Applying: start fix iss2 ...