Use Theirs With Git Merge | Delft Stack
文章推薦指數: 80 %
Use --strategy-option to Resolve Conflicts in Git GitHowtosGitRepositoryNamesSetandSaveUserCredentialsinGitConfigureGitBashWithVisualStudioCodeCreateGroupsandMoveProjectsinGitLabFatal:RefusingtoMergeUnrelatedHistoriesErrorinGitFatal:TheRemoteEndHungUpUnexpectedlyErrorinGitUseGitRebaseontheCommandLineSearchforSpecificStringintheGitCommitHistoryreportthisadHowToGitHowtosUseTheirsWithGitMergeUsethegitmergeCommandWiththeirsinGitUse--strategy-optiontoResolveConflictsinGitUseTemporaryBranchtoMergeinGitWhiledevelopingsoftwarewiththeGittool,youcancreatedifferentbranchesfordifferentfeatures.Buttheremaybeconflictsbetweendifferentbranches.Thisarticlewillexplainusingthegitmergecommandwiththetheirsoptiontoresolveconflicts.UsethegitmergeCommandWiththeirsinGitThegitmergecommandcancombinetwoormoredevelopmenthistories.However,thismergecansometimesnotbedoneduetoconflictsbetweenbranches.Filesinoursortheirsshouldbediscardedtoresolvethisconflict.TheoursreferstotheoriginalworkingbranchwiththeauthorityofGithistory,andthetheirsreferstothebranchthatcontainsthenewappliedcommits.Youcanusethegitmerge-sourstodiscardchangesinours.Thiscommanddiscardsallchangesfromtheotherbranchandleavesthefilesonyourbranchunchanged.Whenyounextmergefromtheotherbranch,Gitwillonlyconsiderchangesmadefromthispointforward.However,the-soptioncannotbeusedwiththeirs.Use--strategy-optiontoResolveConflictsinGitAlternatively,wecanusetheirswiththe-Xor--strategy-optionoption.PleaseenableJavaScriptNotepad++Combineplugin–Combine/MergetwoormorefilesThemaindifferencebetween-Xand-soptionsisthat-Xperformsaregularrecursivemerge,resolvinganyconflictsusingthechosenside,whereas-schangesthemergetojustcompletelyignoretheotherside.Thefollowingcommandresolvesanyconflictsusingthetheirs.gitmerge-Xtheirsbranchname UseTemporaryBranchtoMergeinGitUsethecommandsbelowtomergetest2intocheckedouttest1.Switchtothetest1branch.gitcheckouttest1 Mergethecommitwithoutconflicts.Thecontentsofourswillbediscardedlater.gitmerge-sourstest2 Createatemporarybranch.gitbranchtemp SetHEADwiththegitresetcommand.Itgetscontentsfromthetest2branch.gitreset--hardtest2 Resettomergedcommitbutkeepcontentswiththegitreset--softcommand.gitreset--softtemp Changethemergedcommit’scontentswithtest2’scontents.gitcommit--amend Deletethetemporarybranchwecreatedearlier.gitbranch-Dtemp Youcanseethatthemergedcommitcontainsonlythecontentsoftest2.gitdiffHEADtest2 WriteforusDelftStackarticlesarewrittenbysoftwaregeekslikeyou.IfyoualsowouldliketocontributetoDelftStackbywritingpaidarticles,youcancheckthewriteforuspage.RelatedArticle-GitMergeSelectivelyMergeChangesFromDifferentBranchesinGitMergeFilesWithoutAutoCommitinGitDeleteMergedBranchesinGitUnderstandtheGitConflictMarkersSolveGitPushEverythingUp-To-DateIssueChangetheGitEditorforCommitsreportthisadxx
延伸文章資訊
- 1Git: Handling Merge Conflicts Using "Ours" and "Theirs"
To resolve conflicts during a merge or rebase, we can use git checkout with one of two flags: --o...
- 2Strategies to resolve git conflicts using "theirs" and "ours"
You can use git merge --abort command to abort the merge process when a merge conflict has alread...
- 3git - ours vs theirs
Automatic merge failed; fix conflicts and then commit the result. either fix the conflict manuall...
- 4Advanced Merging - Git SCM
If you pass it diff3 , Git will use a slightly different version of conflict markers, not only gi...
- 5Fixing Git Merge Conflicts: Reference and Examples
Fix all conflicts using "their" changes