0

I'm in the middle of a git merge --squash --no-commit operation. Some files were successfully merged by git, while some other files are indicated as "both modified" (unmerged changes).

I want to commit everything that git was able to merge (including partial changes inside conflicting files), thus leaving only the actual "conflicting sections" to be dealt with later, in a different commit.

Note that if I simply call git commit I receive:

error: commit is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.
William
  • 2,695
  • 1
  • 21
  • 33
  • 1
    You need to resolve the conflicting files, not sure if there is a way out. – Olatunde Garuba Feb 28 '15 at 22:19
  • Yeah, you can't do this. Fix the conflicts first. –  Feb 28 '15 at 22:20
  • I know, but if I do that then the commit will contain also the conflict resolution. I want just to create a commit (let's call it T) that "integrates" new code from a main branch. Then I will create more "fixup" commits for each conflicting change. This is necessary for when my branch will be rebased on the main branch (and T will be deleted). – William Feb 28 '15 at 22:24

2 Answers2

0

Just git add the file before committing, even with the conflict information.

git merge conflicting-branch
git add ./conflicting-file
git commit ...
vvondra
  • 3,022
  • 1
  • 21
  • 34
0

This is the "workaround" I am using, but it's quite tedious:

To convert unmerged changes to unstaged changes call git reset HEAD for each unmerged file. I wonder if there's a better way (git reset has a --merge flag but it doesn't do what I need).

Now the commit "works" but some useful changes (that is: changes that git automatically resolved) will be left unstaged just because they are inside conflicting files. In order to add back these useful changes, call git add -p and go through them all (stage every hunk that is not part of a conflict).

Conclude with git commit (now git diff will return just the conflicts and git difftool will function just as git mergetool would have worked when merging in "the right way").

William
  • 2,695
  • 1
  • 21
  • 33
  • That's pretty much the only option available *unless* you use a different (alternate) index to make the commit. This will let you save the conflict state in the "normal" index. Building that alternate index is just as much work, though, so either way will you still have a rather tedious process. (And I'm not really sure what this accomplishes anyway...) – torek Feb 28 '15 at 23:32