git merge --abort is equivalent to git reset --merge when MERGE_HEAD is present. MERGE_HEAD is present when a merge is in progress.
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
Iranintoamergeconflict.HowdoIabortthemerge?
AskQuestion
Asked
13years,11monthsago
Modified
1monthago
Viewed
2.4mtimes
3037
512
Iusedgitpullandhadamergeconflict:
unmerged:some_file.txt
Youareinthemiddleofaconflictedmerge.
HowdoIabandonmychangestothefileandkeeponlythepulledchanges?
gitversion-controlgit-mergegit-merge-conflict
Share
Follow
editedJul11at6:07
MateenUlhaq
21.9k1616goldbadges8383silverbadges124124bronzebadges
askedSep19,2008at13:21
GwynMorfeyGwynMorfey
31.6k66goldbadges2424silverbadges2121bronzebadges
3
44
Irealisethisisasuper-oldquestion,butdoyouwanttoabortthewholemerge,andleavethebranchyouweremergingunmerged,orjustignorethisonefileaspartofalargermerge,lettingalltheotherfilesmergeinasnormal?Tome,yourtitleimpliestheformer,yourquestionbodywantsthelatter.Theanswersdoboth,withoutmakingthingsclear.
– rjmunro
Oct7,2013at11:18
Igotsimilarcaseoncommitsayingthatautomaticmergefailed;fixconflictsandthencommittheresult:[rejected]gh-pages->gh-pages(non-fast-forward)
– eQ19
Apr30,2016at17:32
4
Gwyn,itcouldbeusefultoselectanacceptedanswerhere.Thetopvotedoneisabitlesssafethansomeofthemoreuptodatesolutions,soIthinkitwouldhelptohighlightothersoverit:)
– Amicable
Oct6,2016at13:11
Addacomment
|
15Answers
15
Sortedby:
Resettodefault
Highestscore(default)
Trending(recentvotescountmore)
Datemodified(newestfirst)
Datecreated(oldestfirst)
2625
SinceyourpullwasunsuccessfulthenHEAD(notHEAD^)isthelast"valid"commitonyourbranch:
gitreset--hardHEAD
Theotherpieceyouwantistolettheirchangesover-rideyourchanges.
Olderversionsofgitallowedyoutousethe"theirs"mergestrategy:
gitpull--strategy=theirsremote_branch
Butthishassincebeenremoved,asexplainedinthismessagebyJunioHamano(theGitmaintainer).Asnotedinthelink,insteadyouwoulddothis:
gitfetchorigin
gitreset--hardorigin
Share
Follow
editedJun28,2017at19:46
RobinDaugherty
6,60033goldbadges4545silverbadges5353bronzebadges
answeredSep19,2008at14:33
PatNotzPatNotz
200k3030goldbadges8989silverbadges9292bronzebadges
12
57
Insteadofdoingahardreset,youcouldbringittoamoregranularlevelbydoing:gitfetchorigin-->gitresetorigin(softreset,yourchangesarestillpresent)-->gitcheckoutfile_to_use_their_version_ofanother_file(steamrollyourownchangesbacktomatchtheorigin)Ineverusegitpullanymore.Sinceinafightbetweenmylatestcodeandtheorigin,theoriginshouldalwayswin,Ialwaysgitfetchandgitrebaseorigin.Thisactuallymakesmymergesandconflictsfewandfarbetween.
– Kzqai
May13,2010at16:20
7
Iagree.Ialsoliketofetchfirst,andthenexaminetheupstreamchanges(gitlog..@{upstream}orgitdiff..@{upstream}).Afterthat,likeyou,I'llrebasemywork.
– PatNotz
May14,2010at23:26
203
Asnotedinamorerecentanswer,asofversion1.6.1,itispossibletouse'gitreset--merge'
– MattBall
Jan23,2012at15:59
5
Iusedgitmerge-Xtheirsremote_branchinsteadofgitpull--strategy=theirsremote_branchastheirslookslikeanoptionofrecursive
– mlt
Jul2,2012at15:28
52
gitmerge--abortisfarpreferable.
– DanielCassidy
Feb24,2016at15:48
|
Show7morecomments
2283
Ifyourgitversionis>=1.6.1,youcanusegitreset--merge.
Also,as@MichaelJohnsonmentions,ifyourgitversionis>=1.7.4,youcanalsousegitmerge--abort.
Asalways,makesureyouhavenouncommittedchangesbeforeyoustartamerge.
Fromthegitmergemanpage
gitmerge--abortisequivalenttogitreset--mergewhenMERGE_HEADispresent.
MERGE_HEADispresentwhenamergeisinprogress.
Also,regardinguncommittedchangeswhenstartingamerge:
Ifyouhavechangesyoudon'twanttocommitbeforestartingamerge,justgitstashthembeforethemergeandgitstashpopafterfinishingthemergeorabortingit.
Share
Follow
editedJan19,2016at23:31
theTinMan
156k4141goldbadges209209silverbadges295295bronzebadges
answeredMar28,2010at23:16
CarlCarl
41.7k1010goldbadges7878silverbadges101101bronzebadges
7
3
Interesting-butthemanualscaresme.Whenexactlyisitappropriatetouse?Whenwouldyouhavetospecifytheoptional?#GitMoment:-o
– conny
Nov15,2011at4:36
1
You'dtypicallyusethiswhenyouwanttoredothemergefromthestart.Ihaveneverhadtospecifytheoptionalcommitmyself,sothedefault(nooptional)isjustfine.
– Carl
Nov15,2011at19:53
54
Iwishthisanswerhadmorevotes!Atthispoint,itseemslikethemostrelevantsolutioninmanycases.
– JayTaylor
Dec7,2011at22:56
1
Evenwithuncommitedchangesgitwasabletorestorethestatebeforethemerge.Nice!
– T3rm1
Jun12,2014at11:45
2
Isgitmerge--abortjustasynonymforgitreset--merge?Thenamecertainlymakesmoresense,butdoesithavethesamefunctionality?
– TikhonJelvis
Jul22,2014at18:37
|
Show2morecomments
622
gitmerge--abort
Abortthecurrentconflictresolutionprocess,andtrytoreconstruct
thepre-mergestate.
Iftherewereuncommittedworktreechangespresentwhenthemerge
started,gitmerge--abortwillinsomecasesbeunableto
reconstructthesechanges.Itisthereforerecommendedtoalways
commitorstashyourchangesbeforerunninggitmerge.
gitmerge--abortisequivalenttogitreset--mergewhen
MERGE_HEADispresent.
http://www.git-scm.com/docs/git-merge
Share
Follow
editedJul16,2015at15:05
HonestAbe
8,02244goldbadges4747silverbadges6262bronzebadges
answeredNov12,2012at21:40
ignisignis
8,44222goldbadges2121silverbadges2020bronzebadges
1
20
Thishasbeenavailablesincegitv1.7.4.It'sanaliasforgitreset--merge.
– MichaelJohnson
Apr24,2013at15:41
Addacomment
|
115
Ithinkit'sgitresetyouneed.
Bewarethatgitrevertmeanssomethingverydifferentto,say,svnrevert-inSubversiontherevertwilldiscardyour(uncommitted)changes,returningthefiletothecurrentversionfromtherepository,whereasgitrevert"undoes"acommit.
gitresetshoulddotheequivalentofsvnrevert,thatis,discardyourunwantedchanges.
Share
Follow
editedMay30,2011at15:47
PeterMortensen
30.3k2121goldbadges100100silverbadges124124bronzebadges
answeredSep19,2008at13:25
DavidPreciousDavidPrecious
6,51311goldbadge2222silverbadges3030bronzebadges
0
Addacomment
|
82
Forgit>=1.6.1:
gitmerge--abort
Forolderversionsofgit,thiswilldothejob:
gitreset--merge
or
gitreset--hard
Share
Follow
editedAug3,2020at18:13
DielsonSales
1,64511goldbadge2222silverbadges2424bronzebadges
answeredJun26,2020at5:36
HanzlaHabibHanzlaHabib
2,9722222silverbadges2525bronzebadges
Addacomment
|
79
Inthisparticularusecase,youdon'treallywanttoabortthemerge,justresolvetheconflictinaparticularway.
Thereisnoparticularneedtoresetandperformamergewithadifferentstrategy,either.Theconflictshavebeencorrectlyhighlightedbygitandtherequirementtoaccepttheothersideschangesisonlyforthisonefile.
Foranunmergedfileinaconflictgitmakesavailablethecommonbase,localandremoteversionsofthefileintheindex.(Thisiswheretheyarereadfromforuseina3-waydifftoolbygitmergetool.)Youcanusegitshowtoviewthem.
#commonbase:
gitshow:1:_widget.html.erb
#'ours'
gitshow:2:_widget.html.erb
#'theirs'
gitshow:3:_widget.html.erb
Thesimplestwaytoresolvetheconflicttousetheremoteversionverbatimis:
gitshow:3:_widget.html.erb>_widget.html.erb
gitadd_widget.html.erb
Or,withgit>=1.6.1:
gitcheckout--theirs_widget.html.erb
Share
Follow
editedMar25,2010at11:54
answeredSep20,2008at10:41
CBBaileyCBBailey
710k9999goldbadges621621silverbadges648648bronzebadges
4
5
thanksforthehint.doesn'tthissmackofapoorgituserinterface,though?
– Peter
Jan12,2010at8:30
@Peter:I'mnotconvinced.Thedesiredresultisachievablewithafewbasiccommandswithsimpleoptions.Whatimprovementswouldyousuggest?
– CBBailey
Mar25,2010at11:58
10
Ithinkthegit1.6.1commandmakesalotofsense,andisgood.That'sexactlywhatIwouldhavewanted.Ithinkthepre-1.6.1solutionisinelegantandrequiresknowledgeaboutotherpartsofgitthatshouldbeseparatedfromthemergeresolutionprocess.Butthenewversionisgreat!
– Peter
Mar27,2010at20:51
Well,withoutcommentingonwhetherit's"poor"ornot,letmesaythatIwouldneverhaveguessedthatasyntaxinvolving'show'and:1:,:2:,and:3:wasthewaytorecoverthebaseandtwo"tip"files,butIamimmenselygladtoknowofthistechnique,so:thankyouverymuch!
– SteveSummit
Mar8at0:28
Addacomment
|
72
Youcaneitherabortthemergestep:
gitmerge--abort
elseyoucankeepyourchanges(onwhichbranchyouare)
gitcheckout--oursfile1file2...
otherwiseyoucankeepotherbranchchanges
gitcheckout--theirsfile1file2...
Share
Follow
answeredNov26,2020at9:20
DARK_C0D3RDARK_C0D3R
1,7991515silverbadges2121bronzebadges
Addacomment
|
59
Commentssuggestthatgitreset--mergeisanaliasforgitmerge--abort.Itisworthnoticingthatgitmerge--abortisonlyequivalenttogitreset--mergegiventhataMERGE_HEADispresent.Thiscanbereadinthegithelpformergecommand.
gitmerge--abortisequivalenttogitreset--mergewhenMERGE_HEADispresent.
Afterafailedmerge,whenthereisnoMERGE_HEAD,thefailedmergecanbeundonewithgitreset--merge,butnotnecessarilywithgitmerge--abort.Theyarenotonlyoldandnewsyntaxforthesamething.
Personally,Ifindgitreset--mergemuchmorepowerfulforscenariossimilartothedescribedone,andfailedmergesingeneral.
Share
Follow
editedJan22,2020at11:47
answeredApr2,2015at12:16
MartinGMartinG
16.2k99goldbadges8080silverbadges9393bronzebadges
5
2
whatishereactuallymeantby"failedmerge"?Mergewithconflictsorsomethingelse?Ortorephraseit:whenisMERGE_HEADnotpresent?Myfollow-upquestionistheretounderstandbetteruseof"gitreset--merge".
– Ewoks
Sep28,2015at8:14
1
@Ewoksgitstashapplycausedamergeconflictformebutgitmerge--abortdidnothelpwhilegitreset--mergedid.
– nitzel
Dec6,2018at14:34
1
Hadtousethistoresolveafailedmerge,IhadnoMERGE_HEADforsomereasonsogitmerge--abortdidn'twork.
– BjornW
Mar20,2021at15:43
Headsuptoanyoneelseconsideringthis:MERGE_HEADisnotpresentwhenyourmergehappenedbecauseofstashpop;andreset--mergewilldeleteyouruntrackedfiles.Seestackoverflow.com/a/67099267/1623757
– Luis
Oct21,2021at19:39
1
WhatIneededafterafailedmergefromatagtomaster...
– Kheldar
Dec8,2021at11:14
Addacomment
|
30
Ifyouendupwithmergeconflictanddoesn'thaveanythingtocommit,butstillamergeerrorisbeingdisplayed.Afterapplyingallthebelowmentionedcommands,
gitreset--hardHEAD
gitpull--strategy=theirsremote_branch
gitfetchorigin
gitreset--hardorigin
Pleaseremove
.git\index.lock
File[cutpastetosomeotherlocationincaseofrecovery]andthenenteranyofbelowcommanddependingonwhichversionyouwant.
gitreset--hardHEAD
gitreset--hardorigin
Hopethathelps!!!
Share
Follow
editedJan22,2020at10:44
Geo
2,00111goldbadge1010silverbadges1919bronzebadges
answeredApr10,2018at21:26
NiravMehtaNiravMehta
6,76399goldbadges4141silverbadges5151bronzebadges
Addacomment
|
21
Analternative,whichpreservesthestateoftheworkingcopyis:
gitstash
gitmerge--abort
gitstashpop
Igenerallyadviseagainstthis,becauseitiseffectivelylikemerginginSubversionasitthrowsawaythebranchrelationshipsinthefollowingcommit.
Share
Follow
answeredJul13,2010at18:57
AlainO'DeaAlainO'Dea
20k11goldbadge5353silverbadges7878bronzebadges
4
IfoundthisapproachusefulwhenIaccidentallymergedtoagit-svnbranch,whichdoesn'thandlethatnicely.Squashmergesorcherrypicksarebetterwhenworkingwithgit-svntrackingbranches.Ineffectmysolutionturnsamergeintoasquashmergeafterthefact.
– AlainO'Dea
Jul13,2010at18:58
1
Bestanswertothequestion
– FouadBoukredine
Feb29,2020at1:36
Howwouldthisbedifferenttoasoftreset?Asoftresetalsoresetstherepositorytoheadbutdoesn'ttouchtheworkingcopy.
– Mecki
Sep4,2020at14:53
Yes,butdoes"gitreset--softsomeref"springtomindwhenyourgoalis"HowcanIabortthemerge?".Howdoyouknowwhattouseforsomeref?Hence"gitmerge--abort"whichdoestherightthingandisobviouslynamedwhichisrefreshingforGit.
– AlainO'Dea
Sep4,2020at14:56
Addacomment
|
18
SinceGit1.6.1.3gitcheckouthasbeenabletocheckoutfromeithersideofamerge:
gitcheckout--theirs_widget.html.erb
Share
Follow
editedJul23,2014at17:45
PeterMortensen
30.3k2121goldbadges100100silverbadges124124bronzebadges
answeredJul17,2010at1:29
AlainO'DeaAlainO'Dea
20k11goldbadge5353silverbadges7878bronzebadges
Addacomment
|
14
MightnotbewhattheOPwanted,butformeItriedtomergeastablebranchtoafeaturebranchandthereweretoomanyconflicts.
Ididn'tmanagetoresetthechangessincetheHEADwaschangedbymanycommits,Sotheeasysolutionwastoforcecheckouttoastablebranch.
youcanthencheckouttotheotherbranchanditwillbeasitwasbeforethemerge.
gitcheckout-fmaster
gitcheckoutside-branch
Share
Follow
answeredJul29,2021at12:56
DanielDaniel
1,66444silverbadges1515bronzebadges
Addacomment
|
4
Toavoidgettingintothissortoftroubleonecanexpandonthegitmerge--abortapproachandcreateaseparatetestbranchbeforemerging.
Case:Youhaveatopicbranch,itwasn'tmergedbecauseyougotdistracted/somethingcameup/youknowbutitis(orwas)ready.
Nowisitpossibletomergethisintomaster?
Workinatestbranchtoestimate/findasolution,thenabandonthetestbranchandapplythesolutioninthetopicbranch.
#Checkoutthetopicbranch
gitcheckouttopic-branch-1
#Createa_test_branchontopofthis
gitcheckout-btest
#Attempttomergemaster
gitmergemaster
#Ifitfailsyoucanabandonthemerge
gitmerge--abort
gitcheckout-
gitbranch-Dtest#wedon'tcareaboutthisbranchreally...
Workonresolvingtheconflict.
#Checkoutthetopicbranch
gitcheckouttopic-branch-1
#Createa_test_branchontopofthis
gitcheckout-btest
#Attempttomergemaster
gitmergemaster
#resolveconflicts,runitthroughtests,etc
#then
gitcommit
#You*could*nowevencreateaseparatetestbranchontopofmaster
#andseeifyouareabletomerge
gitcheckoutmaster
gitcheckout-bmaster-test
gitmergetest
Finallycheckoutthetopicbranchagain,applythefixfromthetestbranchandcontinuewiththePR.
Lastlydeletethetestandmaster-test.
Involved?Yes,butitwon'tmesswithmytopicormasterbranchuntilI'mgoodandready.
Share
Follow
editedJul4,2021at12:30
marc_s
710k170170goldbadges13111311silverbadges14291429bronzebadges
answeredJun10,2021at7:27
sastorslsastorsl
1,8431414silverbadges1616bronzebadges
Addacomment
|
3
Ifoundthefollowingworkedforme(revertasinglefiletopre-mergestate):
gitreset*currentBranchIntoWhichYouMerged*--*fileToBeReset*
Share
Follow
answeredOct31,2017at0:56
MalcolmBoekhoffMalcolmBoekhoff
9421010silverbadges77bronzebadges
Addacomment
|
-11
Sourcetree
Becauseyounotcommityourmerge,thenjustdoubleclickonanotherbranch(whichmeancheckoutit)andwhensourcetreeaskyouaboutdiscardingallchangesthenagree.
Note
ThisanswerisaddressedtothosewhouseSourceTreeasgitclient.
Share
Follow
editedNov28,2021at15:41
Nimantha
6,51566goldbadges2323silverbadges6060bronzebadges
answeredFeb21,2020at16:19
KamilKiełczewskiKamilKiełczewski
74.1k2626goldbadges335335silverbadges305305bronzebadges
3
2
TheOPisobviouslyusingthecommandline.Thereiszerovaluetoyourpost.
– AdrianBartholomew
Dec15,2020at19:52
IagreethatthisisobviousthatOPusecommandline-butpeoplewhonotusecommandlinebutsourcetreeandhavesimilarproblemfindthisquestionatthetopingoogle(likeI)-soforsuchpersonsthisanswerhasvalue-thisiswhyIleftithere:)
– KamilKiełczewski
Dec15,2020at22:33
Noreallybecauseamergeconflictcouldbefordifferentreasons.NeverthelessbehindwhatyoudoonGUIinSourceTree,arerunningcommandlinecommand.OntopIwouldsaybecarefulwithGUIbecauseanyunexpectedsuchlowinternetconnectionwillcauseyourGUItogooutofsyncwithgitindexandyoumayfaceacorruptedflowwithagit.lockthatishardto"fix"excepttoremoveit,andabortthemergeconflict
– CarmineTambascia
Feb16at9:08
Addacomment
|
Highlyactivequestion.Earn10reputation(notcountingtheassociationbonus)inordertoanswerthisquestion.Thereputationrequirementhelpsprotectthisquestionfromspamandnon-answeractivity.
Nottheansweryou'relookingfor?Browseotherquestionstaggedgitversion-controlgit-mergegit-merge-conflictoraskyourownquestion.
TheOverflowBlog
Ahistoryofopen-sourcelicensingfromalawyerwhohelpedblazethetrail...
Thelasttechnicalinterviewyou’llevertake
FeaturedonMeta
PlannedmaintenancescheduledforTuesday,August23,2022at00:00-03:00AM...
PleasewelcomeValuedAssociate#1301-Emerson
StagingGroundWorkflow:QuestionLifecycle
AnnouncingDesignAccessibilityUpdatesonSO
Shouldweburninatethe[maintenance]tag?
Linked
14
SourceTreeGIT-Howtocancelamerge
11
git:error:youneedtoresolveyourcurrentindexfirst
6
WhydoIhave(master|MERGING)onthecommandlineandhowdoIgetridofit?
5230
HowdoIresolvemergeconflictsinaGitrepository?
926
Howtoundoagitmergewithconflicts
798
Undogitstashpopthatresultsinmergeconflict
255
gitstatusshowsmodifications,gitcheckout--doesn'tremovethem
373
HowdoIfinishthemergeafterresolvingmymergeconflicts?
162
Gitstashpop-needsmerge,unabletorefreshindex
119
GitmergeleftHEADmarksinmyfiles
Seemorelinkedquestions
Related
7729
HowdoIremovelocal(untracked)filesfromthecurrentGitworkingtree?
3914
Undoingagitrebase
5230
HowdoIresolvemergeconflictsinaGitrepository?
1680
HowcanIselectivelymergeorpickchangesfromanotherbranchinGit?
2041
Howdoyoustashanuntrackedfile?
24643
HowdoIundothemostrecentlocalcommitsinGit?
3313
CommitonlypartofafileinGit
2448
HowdoIshowthechangeswhichhavebeenstaged?
2528
HowdoIsafelymergeaGitbranchintomaster?
1773
ResolveGitmergeconflictsinfavoroftheirchangesduringapull
HotNetworkQuestions
FantasyinAsimov'smagazine-wordsthatcausebadlucktoanyonewhoreadsthem
RadicalIQchallenge
StandbytravelonKoreanAirviaICN
DartmouthBASICarraydimensionsquestion
Whenisb6a#5inmajormode?
CanaMastergraduatedstudentbeaparticipantinascientificconference?
SplittingcolumnsinTSVintoCSV
Findawaytoexpressanevennumberasthesumof2evennumbers
WhyarethespeedbrakesontheF-86deployedwhenparked?
WhyarebeansIsoakmyselfalwayssmallerthancanned?
Is"createnew"notpleonastic?
Arethereanyprobabilisticmodelsforthelikelihoodoffindingarogueplanetclosertousthanproximacentauri?
Studentkeepsaskingaboutattendancepolicy
Diffie-HellmanoverGF(2^128)
CannotinstallAndroidEmulatorviaAndroidStudioinMacbookM1Pro
Howto(relativelysafely)storeasmallamount(200milliliters)ofgasolineforuptoamonth?
WhycanIseedatabelongingtoWindowsfromUbuntu(dual-booted)?
WhyisManchintheonlyDemocraticSenatorleveragingthe50/50votesplitforthebenefitoftheirstate?
Howtodoinfiniteloopusingdowhileandbreakifsomethingfailed?
Areoptimizationresultsstochastic?
Whatis'crying'in'Shesawhimcrying.'
Whydoesn'tAuthorityoftheConsulspreventthegoblintokenfromDenoftheBugbearfromattacking?
Howwasthistextureeffectachieved?
HowcanIfindmagicitemsintendedforaspecificclassonD&DBeyond?
morehotquestions
Questionfeed
SubscribetoRSS
Questionfeed
TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader.
Yourprivacy
Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy.
Acceptallcookies
Customizesettings