开发者

Git - how to always take a my branch's content when hitting a conflict?

开发者 https://www.devze.com 2023-01-06 18:22 出处:网络
I saw the post \"How do I tell git to always select my local version for conflicted merges on a specific file?\", which says if you have conflict on a folder, we need to add .gitattributes to that fol

I saw the post "How do I tell git to always select my local version for conflicted merges on a specific file?", which says if you have conflict on a folder, we need to add .gitattributes to that folder 开发者_开发知识库and then add a merge driver to config file to say always keep my branch's content for this folder.

And this works perfectly fine.

But what if I end with up conflicts on several folders/files and want to keep my version for these. It doesn't make sense to create .gitattributes file in every folder that has conflicts.

So is there a way to do this - like if am merging Branch-A to Branch-B and end up with so many conflicts, I need a way by which I can keep Branch-B contents for all the conflicts.

Any help is appreciated.


If you want to take branch B's version for all conflicts, you can simply use a merge strategy option:

git merge -X ours branchB

This will merge normally (using the default recursive strategy) until it runs into a conflicting hunk, at which point it'll automatically take branch B's version of the hunk.

0

精彩评论

暂无评论...
验证码 换一张
取 消