Subject: Re: can't commit files that have been git add'ed because "fatal: you need to resolve your current index first"

From: Jakub Narebski <[email-masked]>
Date: Wed, 28 Nov 2007 17:55:10 +0100

Please do not toppost, and try not to break quoted lines, please.
Thanks in advance.

On Wed, 28 Nov 2007, Bill Priest wrote:
> --- Jakub Narebski <[email-masked]> wrote:
>> Bill Priest wrote:
>> 
>>>   I merged from one branch to another and had lots of
>>> conflicts.  I've resolved a set of files from the
>>> conflicts (in a directory) and did a git-add on this
>>> set of files.  I wasn't able to commit these files. 
>>> On IRC I was told that all files must be resolved
>>> before I can commit any of them.  This seems pretty
>>> limiting.  Why is a commit after a merge all or
>>> nothing; I thought that git  figured out merges and
>>> such by the differences between files??
>> 
>> You have to resolve _conflicts_ only. The rest is
>> added
>> automatically. See git-status, git diff --merge,
>> git ls-files -u.

>    I understand that git requires this.  My question
> is   git enforcing policy or is there something
> "magic" about a commit after a merge.  What if I want
> to make an independent change and check it in on the
> same branch before I am finished with the merge? 

A little technical information about failed merge.

First, git tries to merge as mauch as it can automatically,
doing tree-level merge and trying three-way file-level merge
if necessary. Everything that merges cleanly is automatically
added to staging area.

For each file that has unresolved conflicts git adds to staging
are all (three) versions of file: original, from merged in
branch, and common ancestor version, as stages 1, 2, 3 (not
necessary in this order: see documentation). Additionally it
leaves partially merged file in working area with RCS-like
conflicts markes in it. (Note that default checking before
commits refuses to check in file with conflict markers; see
documentation how to force commit anyway).

Additionally git records the fact that it is in the midle of merge
by recording branch(es) merged in in .git/MERGE_HEAD.

To resolve conflicts you have to bring file to some version,
removing conflict markers, add this version using "git add",
then commit.

You can try to git-stash partially done merge; if it doesn't
work send us bugreport.

-- 
Jakub Narebski
Poland