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
延伸文章資訊
- 1Resolve Git merge conflicts in favor of their changes during a ...
git pull -X theirs creates a merge commit if there are conflicts (e.g. if another committer ran g...
- 2git - ours vs theirs
Automatic merge failed; fix conflicts and then commit the result. either fix the conflict manuall...
- 3Quickest Way to Resolve Most Merge Conflicts - Git
Find files with merge conflict ... Change working directory to project folder. ... Search for all...
- 4Fixing Git Merge Conflicts: Reference and Examples
Fix all conflicts using "their" changes
- 5Advanced Merging - Git SCM
If you pass it diff3 , Git will use a slightly different version of conflict markers, not only gi...