8

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!

Micah
  • 111,873
  • 86
  • 233
  • 325
  • Are you sure it didn't just give you an error because you put an option after the path instead of before it? – Cascabel May 12 '10 at 20:16
  • 1
    Also, there's always `git merge -Xours`, which resolves conflicts by using "our" version. (The "ours" option is passed through to the recursive merge strategy.) – Cascabel May 12 '10 at 20:17
  • Oh, I see what you mean - you're getting an error from the commit, not the checkout. Answer time! – Cascabel May 12 '10 at 20:21
  • It seems intuitive for git to accept all files whose <<<, >>>, and === signs have been eliminated. – John Jiang Jul 06 '20 at 18:49

4 Answers4

11

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!

Cascabel
  • 479,068
  • 72
  • 370
  • 318
4

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Ah, good call. I was assuming that the OP still wanted to (or had to) manually grab the correct versions of the files, but since they're generated files it should be possible to target them all with a merge driver! – Cascabel May 13 '10 at 17:58
2

No native git support, but you can try the following hack:

git status | grep "both modified:" | awk '{print $NF}' | xargs git add

To be safe, run the command without xargs first to inspect the files to be added.

John Jiang
  • 827
  • 1
  • 9
  • 19
0

For this case, using regex will help for staging.

After resolution of conflict, to add files that are in unmerged paths, you can use common identifier of the files.

For example, if few text files and xml files need to be committed, extensions on files are .txt and .xml, stage the files using the below command.

git add *.txt *.xml

Note: this will add all the .txt and .xml files in the repository, even those which are untracked files.

Shashi
  • 129
  • 1
  • 2
  • 9