9

Git will not let one push a branch that has a merge conflict. In our current situation, there are ~15 conflicting files, some of which are my code and some of which are other people's code. It is preferable that each person who changed code perform the merge on those particular files. How can we all work on our own files to complete the merge?

Unmerged paths:
    both modified:   foo.py        # This I should fix
    both modified:   bar.py        # This Jeff Atwood should fix
    both added:      bin/baz.py    # This Joel Spolsky should fix 
    both added:      bin/buzz.py   # This I should fix

Other than having us all sit down at the same computer, or even at the same terminal via Tmux, how can each person perform the merge on the files which are his responsibility? I know nothing about bar.py, and Jeff knows nothing about how foo.py works.

Kai Mattern
  • 3,090
  • 2
  • 34
  • 37
dotancohen
  • 30,064
  • 36
  • 138
  • 197

2 Answers2

3

This gist does, I believe, what you want. Basically, you merge with --no-ff --no-commit, resolve conflicts, then reset head to un-add the merged stuff, then add only the things you want.

Amadan
  • 191,408
  • 23
  • 240
  • 301
  • Thank might work, thanks. There is a comment at the bottom that shows how each dev can merge just the files that he intends to resolve the conflict for, as well. That might be preferable to the content of the gist. – dotancohen Sep 08 '14 at 06:38
  • If you mean the `git checkout mergeFrom list of files to move`, that will replace your content with his, without merging. – Amadan Sep 08 '14 at 06:45
  • I was hoping that each user would be able to merge just those files that he is to work on, once the list of files needing merging is established (with `git merge somebranch`, `git merge --abort`); – dotancohen Sep 08 '14 at 08:13
  • Yes, merge just those files that he is to work on is exactly right. Just run `git mergetool myFileX` and `git add myFileX` for each file. The trick is in preventing `git merge` from committing all files automatically, and unstaging to prevent committing files you don't want to merge. – Amadan Sep 08 '14 at 08:17
-2

There is a tool here to resolve the conflicts and after resolving the conflicts you can merge that particular file. Use the command "git mergetool" to find the difference between files and choose which one to keep. Here is the documentation for this git-mergetool.

After resolving all the conflicts you can merge the branches.

Bilbo Baggins
  • 2,899
  • 10
  • 52
  • 77
  • Thank you Samwise. The mergetool will help me merge the files which are my responsibility (foo.py, bin/buzz.py). However, it won't let me push the unmerged files (bar.py, bin/baz.py) and I cannot merge those. – dotancohen Sep 08 '14 at 06:32
  • He doesn't want to resolve all the conflicts, only those on `foo.py` and `bin/buzz.py`. – Amadan Sep 08 '14 at 06:32
  • This answer is off-topic because it doesn't address the OP's concerns about not knowing how to resolve conflicts in files coded by other developers... – jub0bs Sep 08 '14 at 06:33
  • No tool can decide which code to keep and which is to be removed, this needs to be done manually and after this you can merge the entire branch. What you can do is let your friends resolve their conflicts, ask them to commit to the same branch where you are working and then take an update, after this you can merge the branch. – Bilbo Baggins Sep 08 '14 at 06:36