threads / discuss / 11046

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

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

## tl;dr

One message between Nov 28, 2007 and Nov 28, 2007.

replies: 0people: 1as markdown or json

Jakub Narebski· Nov 28, 2007, 16:55 UTC · lore

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

On Wed, 28 Nov 2007, Bill Priest wrote:
Show 17 quoted lines
> --- Jakub Narebski <jnareb@gmail.com> 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.
Show 5 quoted lines
>    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

← back to recent threads