2

I usually have merge conflicts on Rails locale files, for example:

<<<<<<< HEAD
  label_company_offices: "Branches"
=======
  field_amounts_withheld: "Withheld amount"
>>>>>>> master

here I have to edit every locale file, can I avoid this?

there's any way to tell git "resolve conflict accepting both changes"?

Lluís
  • 1,267
  • 1
  • 14
  • 36
  • 3
    There is, sort of. This is called a *union merge*. Don't do it! Or (for experts only): don't do it yet. See http://stackoverflow.com/q/38502458/1256452 for details. – torek Nov 18 '16 at 09:10
  • thanks for the link, I searched but wasn't able to find it :( I don't like the idea to have to check if merge was made correctly every time, if git doesn't support this, I think a script with `sed` can do the job – Lluís Nov 18 '16 at 10:38

2 Answers2

1

this does the job for me:

ruby -pi -e "gsub(/^[=<>*]{7}.*\n/,'')" config/locales/*.yml

used in a bash alias:

alias automerge="ruby -pi -e \"gsub(/^[=<>*]{7}.*\\n/,'')\""
Lluís
  • 1,267
  • 1
  • 14
  • 36
-1

You should be manually resolving all merge conflicts before re-staging them ("git add") and completing the merge commit.

The only way to "accept both" would be to just re-stage (marking as resolved) the conflicted files without resolving them ( >>> and <<< would be there still), but your result couldnt be compiled or executed. And this is terrible practice, even if you make commits later to resolve. The point of the merge commit is to see the resolution of the merge in the commit.

There are ways to avoid generating the conflicts - using merge strategies. For example, you can pass a strategy parameter to the "git merge" command to always take your change in a conflict using the "ours" strategy. Look at the "git merge" help page to see the different strategies and maybe one will apply to your situation.

kburch
  • 7
  • 3
  • what I want is to automatically remove the git marks so then I can do `git add` and accept both changes – Lluís Nov 21 '16 at 23:03