Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accept all merge conflicts in git

Tags:

git

merge

I'm trying to do a merge and there's a bunch of conflicts. It's all generated files so what I want to do is basically say "ignore all merge conflicts, and check everything in from my own repo".

I've tried

git checkout . --ours
git add -A
git com -a

It gives me an error though because there are still files in the "unmerged paths" bucket. How do I handle this?

Thanks!

like image 980
Micah Avatar asked May 12 '10 20:05

Micah


2 Answers

Git commands are very wary of hiding conflicts - you pretty much have to explicitly check in a conflicted file to let it know that it's fixed. It does seem odd that there's not a -f style option for git add to let it know you really mean it, but here's an alias that I have which will help:

add-unmerged = \
    "!f() { git ls-files --unmerged | cut -f2 | sort -u ; }; git add `f`"

Bonus tip: if you change "git add" to $EDITOR, you now have edit-unmerged, for editing all the conflicted files!

like image 160
Cascabel Avatar answered Oct 03 '22 07:10

Cascabel


Use a custom merge driver:
you can declare that driver in a .gitattributes located in the right directory (the one with the generated files whose merge you do not want to deal with)

* merge=keepMine

(you can specify a more precise pattern to isolate the exact files concerned with that custom merge)

with the config:

[merge "keepMine"]
        name = always keep mine during merge
        driver = keepMine.sh %O %A %B

See "How do I tell git to always select my local version for conflicted merges on a specific file?" for a complete example.

like image 32
VonC Avatar answered Oct 03 '22 09:10

VonC