Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would one use "git merge -s ours"?

Tags:

git

merge

I understand that the "ours" merge strategy (hear the quotes around merge?) actually does not use any commits from the other branch.

The "ours" strategy is sometimes mentioned as "keeping the other's history". But it records that history as "applied". Weird. Are there cases where I do want this behaviour?

As an alternative, you could just as well import the other branch and let its history there, where it belongs.

Note that I am asking about the "-s ours" strategy, not the "-X ours" option to "-s recursive" (which is different in that it applies those commits that don't conflict).

like image 795
Prestel Nué Avatar asked Feb 22 '11 11:02

Prestel Nué


People also ask

What does git merge ours do?

git merge -s ours. The ours strategy is simple: it discards all changes from the other branch. This leaves the content on your branch unchanged, and when you next merge from the other branch, Git will only consider changes made from this point forward.

What is the best merge strategy in git?

Recursive is the default merge strategy when pulling or merging one branch. Additionally this can detect and handle merges involving renames, but currently cannot make use of detected copies. This is the default merge strategy when pulling or merging one branch.

Why do we need to merge?

Merging is a common practice for developers using version control systems. Whether branches are created for testing, bug fixes, or other reasons, merging commits changes to another location. To be more specific, merging takes the contents of a source branch and integrates them with a target branch.

What is an alternative to merging in git?

While merging is definitely the easiest and most common way to integrate changes, it's not the only one: "Rebase" is an alternative means of integration.


1 Answers

One use is to "skip" a commit made on a maintenance branch that isn't intended to go back into your main/trunk branch of development. See this previous question for an example: git - skipping specific commits when merging

like image 180
araqnid Avatar answered Sep 22 '22 07:09

araqnid