Resolving a merge conflict using the command line

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

Competing line change merge conflicts · Open TerminalTerminalGit Bash. · Navigate into the local Git repository that has the merge conflict. · Generate a list of ... SkiptomaincontentGitHubDocsAllproductsPullrequestsCommitchangestoyourprojectCreate&editcommitsAboutcommitsWithmultipleauthorsOnbehalfofanorganizationChangingacommitmessageView&comparecommitsComparingcommitsCommitviewsTroubleshootingcommitsCommitmissinginlocalcloneLinkedtowronguserCollaboratewithpullrequestsGettingstartedCollaborativedevelopmentWorkingwithforksAboutforksConfigurearemoteSyncingaforkAllowchangestoabranchDeletedorchangesvisibilityCodequalityfeaturesAboutstatuschecksProposechangesAboutbranchesCreate&deletebranchesAboutpullrequestsComparebranchesCreatingapullrequestCreateaPRfromaforkUsingqueryparameterstocreateapullrequestChangethestateRequestaPRreviewUpdatetheheadbranchChangethebasebranchCommittoPRbranchfromforkAddressmergeconflictsAboutmergeconflictsResolvemergeconflictsResolvemergeconflictsinGitReviewchangesAboutPRreviewsReviewproposedchangesFilterfilesMethods&functionsCommentonaPRViewaPRreviewReviewdependencychangesIncorporatefeedbackRequiredreviewsDismissaPRreviewCheckoutaPRlocallyIncorporatechangesAboutpullrequestmergesMergingapullrequestMergePRautomaticallyMergePRwithmergequeueClosingapullrequestRevertingapullrequestResolvingamergeconflictusingthecommandlineInthisarticleCompetinglinechangemergeconflictsRemovedfilemergeconflictsFurtherreadingYoucanresolvemergeconflictsusingthecommandlineandatexteditor.MacWindowsLinuxMergeconflictsoccurwhencompetingchangesaremadetothesamelineofafile,orwhenonepersoneditsafileandanotherpersondeletesthesamefile.Formoreinformation,see"Aboutmergeconflicts." Tip:YoucanusetheconflicteditoronGitHubtoresolvecompetinglinechangemergeconflictsbetweenbranchesthatarepartofapullrequest.Formoreinformation,see"ResolvingamergeconflictonGitHub." Competinglinechangemergeconflicts Toresolveamergeconflictcausedbycompetinglinechanges,youmustchoosewhichchangestoincorporatefromthedifferentbranchesinanewcommit. Forexample,ifyouandanotherpersonbotheditedthefilestyleguide.mdonthesamelinesindifferentbranchesofthesameGitrepository,you'llgetamergeconflicterrorwhenyoutrytomergethesebranches.Youmustresolvethismergeconflictwithanewcommitbeforeyoucanmergethesebranches. OpenTerminalTerminalGitBash. NavigateintothelocalGitrepositorythathasthemergeconflict. cdREPOSITORY-NAME Generatealistofthefilesaffectedbythemergeconflict.Inthisexample,thefilestyleguide.mdhasamergeconflict. $gitstatus >#Onbranchbranch-b >#Youhaveunmergedpaths. >#(fixconflictsandrun"gitcommit") ># >#Unmergedpaths: >#(use"gitadd..."tomarkresolution) ># >#bothmodified:styleguide.md ># >nochangesaddedtocommit(use"gitadd"and/or"gitcommit-a") Openyourfavoritetexteditor,suchasAtom,andnavigatetothefilethathasmergeconflicts. Toseethebeginningofthemergeconflictinyourfile,searchthefilefortheconflictmarker<<<<<<<.whenyouopenthefileinyourtexteditor>>>>>>>BRANCH-NAME.Inthisexample,onepersonwrote"openanissue"inthebaseorHEADbranchandanotherpersonwrote"askyourquestioninIRC"inthecomparebranchorbranch-a. Ifyouhavequestions,please <<<<<<>>>>>>branch-a Decideifyouwanttokeeponlyyourbranch'schanges,keeponlytheotherbranch'schanges,ormakeabrandnewchange,whichmayincorporatechangesfrombothbranches.Deletetheconflictmarkers<<<<<<>>>>>>andmakethechangesyouwantinthefinalmerge.Inthisexample,bothchangesareincorporatedintothefinalmerge: Ifyouhavequestions,pleaseopenanissueoraskinourIRCchannelifit'smoreurgent. Addorstageyourchanges. $gitadd. Commityourchangeswithacomment. $gitcommit-m"Resolvedmergeconflictbyincorporatingbothsuggestions." YoucannowmergethebranchesonthecommandlineorpushyourchangestoyourremoterepositoryonGitHubandmergeyourchangesinapullrequest. Removedfilemergeconflicts Toresolveamergeconflictcausedbycompetingchangestoafile,whereapersondeletesafileinonebranchandanotherpersoneditsthesamefile,youmustchoosewhethertodeleteorkeeptheremovedfileinanewcommit. Forexample,ifyoueditedafile,suchasREADME.md,andanotherpersonremovedthesamefileinanotherbranchinthesameGitrepository,you'llgetamergeconflicterrorwhenyoutrytomergethesebranches.Youmustresolvethismergeconflictwithanewcommitbeforeyoucanmergethesebranches. OpenTerminalTerminalGitBash. NavigateintothelocalGitrepositorythathasthemergeconflict. cdREPOSITORY-NAME Generatealistofthefilesaffectedbythemergeconflict.Inthisexample,thefileREADME.mdhasamergeconflict. $gitstatus >#Onbranchmain >#Yourbranchand'origin/main'havediverged, >#andhave1and2differentcommitseach,respectively. >#(use"gitpull"tomergetheremotebranchintoyours) >#Youhaveunmergedpaths. >#(fixconflictsandrun"gitcommit") ># >#Unmergedpaths: >#(use"gitadd/rm..."asappropriatetomarkresolution) ># ># deletedbyus:README.md ># >#nochangesaddedtocommit(use"gitadd"and/or"gitcommit-a") Openyourfavoritetexteditor,suchasAtom,andnavigatetothefilethathasmergeconflicts. Decideifyouwantkeeptheremovedfile.Youmaywanttoviewthelatestchangesmadetotheremovedfileinyourtexteditor. Toaddtheremovedfilebacktoyourrepository: $gitaddREADME.md Toremovethisfilefromyourrepository: $gitrmREADME.md >README.md:needsmerge >rm'README.md' Commityourchangeswithacomment. $gitcommit-m"ResolvedmergeconflictbykeepingREADME.mdfile." >[branch-d6f89e49]Mergebranch'branch-c'intobranch-d YoucannowmergethebranchesonthecommandlineorpushyourchangestoyourremoterepositoryonGitHubandmergeyourchangesinapullrequest. Furtherreading "Aboutmergeconflicts" "Checkingoutpullrequestslocally"



請為這篇文章評分?