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 --the开发者_高级运维irs <filename>
git add <filename>
git commit
Is this correct, or am I missing something?
I'd like to do it without using .gitignore
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.
Look into using .gitignore to ignore generated files. You may have to do git rm as well.
精彩评论