Resolving a merge conflict using the command line
文章推薦指數: 80 %
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"
延伸文章資訊
- 1合併發生衝突了,怎麼辦? - 為你自己學Git | 高見龍
git status On branch cat You have unmerged paths. (fix conflicts and run "git commit") (use "git ...
- 2git遇到衝突了怎麼辦?別緊張,解衝後就好了。 - iT 邦幫忙
When we use git merge to merge two branches, git has its own way to determine whether there is a ...
- 36.解決合併的衝突【教學1 使用分支】 | 連猴子都能懂的Git入門 ...
$ git merge issue3 Auto-merging myfile.txt CONFLICT (content): Merge conflict in myfile.txt Autom...
- 4本地分支衝突- git - W3HexSchool - 六角學院
git merge dev Auto-merging all.css CONFLICT (content): Merge conflict in all.css Automatic merge ...
- 5Resolving a merge conflict using the command line
Competing line change merge conflicts · Open TerminalTerminalGit Bash. · Navigate into the local ...