15

While resolving merge conflicts, if I don't know which one to pick (because I'm not aware of any of the two changes), I would like to

  1. create a patch, or
  2. create separate branch (kind of), or
  3. anything else which can be done,

so that I can send the conflict to my teammate for him to resolve conflict.

Note: Aborting the merge and asking my teammate to merge is one way in such a situation. However, that would mean all the conflicts that were resolved were a waste of effort, and others who will merge now will have to repeat all the resolutions again. So, that's not an option.

IsmailS
  • 10,797
  • 21
  • 82
  • 134
  • Good idea. Pragmatic alternative is to not merge, I guess, continue to work on your favourite branch and wait for someone else to merge. If you did not make (and do not understand) either change, it seems like it should be someone else's job to clean up after them. – Thilo May 30 '14 at 10:20
  • Should you have already started merge, use `git merge --abort` to let someone else do the work :) – mms27 May 30 '14 at 10:25
  • Was this a merge you invoked yourself, or a merge from pulling changes from a remote? – Mike Dimmick May 30 '14 at 10:29
  • @mms27, thanks. I'm not that newbie to git. Though, hopefully your comment will help many others who may visit here. – IsmailS May 30 '14 at 10:29
  • @MikeDimmick a merge that I invoked. – IsmailS May 30 '14 at 10:30
  • Git *is not capitalized* as "GIT", it's not an abbreviation like TFS, SVN, and CVS. –  May 30 '14 at 13:12
  • Best I can do is send the output of `git diff` and ask for the proper resolutions. The diff will show all remaining conflicts, and any resolutions that don't match either branch (e.g. combine changes from both) with left/right/worktree content. Git doesn't have any facility I can find for recording/transferring a partially-resolved merge. – jthill May 30 '14 at 14:40

2 Answers2

1

You should commit your patch in a different branch. Then the other team-mate should do the merging and solve the conflicts accordingly. Remember to give a nice message of what did you change so if the other person have conflicts with your code he knows what is new.

Do not commit unresolved conflicts since this can be forgotten and give problems in the future.

To create a branch out of the current branch just do

git checkout -b newBranchName

then just commit and push the branch

git commit -m "message here"
git push origin newBranchName

the other person should pull and merge and then erase this new branch if necessary

EDIT:

I saw your update... so, what you should do (though I will not recommend it) is create another branch, add the files that have merge conflict use the git add file command to remove the conflict status, and then in the message of the commit say which files have a conflict....

You should see the logs or use git blame file, to see which parts are new or not. And try to solve them yourself. There is no partial resolution of conflicts in GIT.

api55
  • 11,070
  • 4
  • 41
  • 57
  • I already tried committing. `error: 'commit' is not possible because you have unmerged files. hint: Fix them up in the work tree, hint: and then use 'git add/rm ' as hint: appropriate to mark resolution and make a commit, hint: or use 'git commit -a'. fatal: Exiting because of an unresolved conflict.` – IsmailS May 30 '14 at 10:32
  • `git merge --abort` will undo the merge you started. – gbjbaanb May 30 '14 at 10:33
  • exactly, you need to revert the changes before the merge, as I told you before you can't commit conflicts. You can either go back to your last commit (unless that your last commit is before your changes) or use the command sugested by @gbjbaanb – api55 May 30 '14 at 10:37
  • Oh! then that doesn't answer the question. Sorry, if I wasn't enough clear and if you understood that I'm asking how to make changes and share it with others to merge to mainline. – IsmailS May 30 '14 at 11:03
  • @iSid I updated the question, though I strongly recommend against it. – api55 May 30 '14 at 12:13
1

This is an old post but the simple way of collaborating with others to fix conflicts that you can't resolve is to leave the specific conflicted files as is and commit the same, the collobarator(s) will have to manually fix the conflicts via a text editor - or if they are not comfortable doing thrs - use a diff tool but setup the local, remote etc copies manually). Details:

  • In case you want the current branch (branch you are merging changes into) to be in working condition
    • Abort the current merge with git merge --abort
    • Create a new branch of your current branch to merge into
    • Re-initiate the merge
  • Leave the file unchanged in your mergetool interface (Don't save or accept the auto-merged changes).
  • When git asks if "The file was unchanged, was the merge successful", agree it was a 'success'
  • Do the same for other files where you can't resolve conflicts and finally commit all the changes at the end as usual
    • Consider adding a flag to the unresolved conflicted file in you commit message or at the very least use git commit --no-edit to ensure that the conflicted files are captured in the commit. Preferably add your message but un-comment the lines that indicate the conflicted files and add a flag so that it is easy for collaborators to identify the same as well as helpful to have the same in history

Then your collaborators can look at the conflicted file(s) and manually merge the same via a text editor (or setup the same manually in a merge GUI) at their end by pulling in your branch. Post the resolution and build success, this merge branch can be merged into your actual branch

Deepak
  • 3,648
  • 1
  • 22
  • 17
  • This is a work around which may work but is not that easy. You have to document the remaining merge work and other collaborator will have to search for the conflicts to solve all of the remaining ones without miss. – IsmailS Sep 16 '22 at 18:04