2

Is it possible to merge branch edits into branch master with the following scenario:

many changes were made on edits as well as new files added.

many changes were also made to master as well as new files added.

I'd like to overwrite any duplicate files in master and use the files from edits, so that when im done, master will contain all changes from edits, all new files from edits and all new files from master. If both contained new files, it would use edits's new files. If there are merges, I'd like to replace the entire file with the one from edits.

I found this answer: https://stackoverflow.com/a/1295232/1166285 and tried the comment's suggestion but that made conflicts which i'd have to resolve.

Is this possible?

Community
  • 1
  • 1
d-_-b
  • 21,536
  • 40
  • 150
  • 256

1 Answers1

3

On the master branch, merge in the edits branch with the theirs merge strategy:

git checkout master
git merge -Xtheirs edits

In case of conflicts, this will prefer the theirs branch. Changes from master where there is no conflict will be retained.

Andomar
  • 232,371
  • 49
  • 380
  • 404
  • thanks, does this replace the file completely if there are *some* conflicts? – d-_-b May 19 '13 at 18:42
  • If a single file contains changes on both branches, the ones that do not conflict will make it into the merged file. – Andomar May 19 '13 at 18:48
  • this ended with `Automatic merge failed; fix conflicts and then commit the results` – d-_-b May 19 '13 at 18:50
  • That's surprising! Was the master branch clean, or did it have uncommitted changes? (Check with `git status`.) What kind of changes caused the conflicts? (Check with `git diff --diff-filter=U`) – Andomar May 19 '13 at 18:53
  • git status only has untracked files (in both), and the other command showed nothing – d-_-b May 19 '13 at 19:02
  • The second command displays the merge conflicts. It should show something after an automatic merge fails. – Andomar May 19 '13 at 19:04
  • oh b/c I did a git reset --hard afterwards. That second command would show `* Unmerged path html/file.php` – d-_-b May 19 '13 at 19:16
  • It was because i renamed a file to the same name but all uppercase. Doing `git add -u` afterwards fix it...thanks! – d-_-b May 19 '13 at 19:30