Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a "theirs" version of "git merge -s ours"?

Tags:

git

git-merge

When merging topic branch "B" into "A" using git merge, I get some conflicts. I know all the conflicts can be solved using the version in "B".

I am aware of git merge -s ours. But what I want is something like git merge -s theirs.

Why doesn't it exist? How can I achieve the same result after the conflicting merge with existing git commands? (git checkout every unmerged file from B)

The "solution" of just discarding anything from branch A (the merge commit point to B version of the tree) is not what I am looking for.

like image 804
elmarco Avatar asked Oct 06 '08 11:10

elmarco


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 are the different types of git merge?

Git merging combines sequences of commits into one unified history of commits. There are two main ways Git will merge: Fast Forward and Three way. Git can automatically merge commits unless there are changes that conflict in both commit sequences.

Is git pull the same as merge?

The git pull command first runs git fetch which downloads content from the specified remote repository. Then a git merge is executed to merge the remote content refs and heads into a new local merge commit.


1 Answers

A similar alternative is the --strategy-option (short form -X) option, which accepts theirs. For example:

git checkout branchA git merge -X theirs branchB 

However, this is more equivalent to -X ours than -s ours. The key difference being that -X performs a regular recursive merge, resolving any conflicts using the chosen side, whereas -s ours changes the merge to just completely ignore the other side.

In some cases, the main problem using -X theirs instead of the hypothetical -s theirs is deleted files. In this case, just run git rm with the name of any files that were deleted:

git rm {DELETED-FILE-NAME} 

After that, the -X theirs may work as expected.

Of course, doing the actual removal with the git rm command will prevent the conflict from happening in the first place.

like image 69
Alan W. Smith Avatar answered Sep 28 '22 11:09

Alan W. Smith