Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git merging theirs steps

Tags:

git

merge

I am dealing with quite a few binary files generated by a program. Auto merging doesn't work well for these files. What I'd like to do when merging, is quite literally take one copy or the other. It's not ideal, but I think it's the best approach.

Now my understanding, is that if I wanted to take a file from the branch I'm merging from, and completely discard our version, I should do:

git merge <branchname> git checkout --theirs <filename> git add <filename> git commit 

Is this correct, or am I missing something?

I'd like to do it without using .gitignore

like image 557
Dominic Bou-Samra Avatar asked Apr 15 '11 01:04

Dominic Bou-Samra


People also ask

What does git merge theirs do?

Merging is Git's way of putting a forked history back together again. The git merge command lets you take the independent lines of development created by git branch and integrate them into a single branch.

Does merging affect both branches?

So merging one branch into another has a secondary effect: it moves the merge base of those two branches. In particular, the new merge base of the two branches is now the second parent of the merge commit.

What is git 3 way merge?

A three-way merge involves three snapshots. Two are the ones that are involved in a two-way merge, and the third one is the base file or the common ancestor with which these two files will be compared. As you can see, C3 is the common ancestor with which C4 and F3 will be compared for merging.


2 Answers

If your goal is indeed to keep one version or the other, then yes, you will want to use:

git checkout <--theirs|--ours> <path> git add <path> 

Of course, as you say, it's not ideal. If there's any way you can avoid this, you should. If you can, try to adopt workflow habits which avoid changing those files on divergent branches which will later need to be merged. If the files are generated from tracked content, you really probably do want to ignore them - if you have good reason not to, you might want to generate them from the mergeable tracked content instead, if that's possible.

So, explore all your other options before doing this, but if you must, you've got it right.

like image 63
Cascabel Avatar answered Oct 13 '22 23:10

Cascabel


Look into using .gitignore to ignore generated files. You may have to do git rm as well.

like image 30
Justin Thomas Avatar answered Oct 13 '22 22:10

Justin Thomas