From: Junio C Hamano <gitster@pobox.com>
To: Bill Priest <priestwilliaml@yahoo.com>
Cc: git@vger.kernel.org
Subject: Re: can't commit files that have been git add'ed because "fatal: you need to resolve your current index first"
Date: Wed, 28 Nov 2007 12:08:40 -0800 [thread overview]
Message-ID: <7v63zm5e0n.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <820179.5481.qm@web55002.mail.re4.yahoo.com> (Bill Priest's message of "Wed, 28 Nov 2007 07:48:27 -0800 (PST)")
Bill Priest <priestwilliaml@yahoo.com> writes:
> 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.
You have two parallel development lines that lead to A and B and trying
to come up with a "merge" M:
o---o---A
/ \
---o---o---B---M
What property should the merge commit "M" have? It must keep the
changes made on the upper line to make it better than B, and it must
keep the changes made on the lower line to make it better than A.
Let's say both upper and lower lines of development touched files frotz
and xyzzy in overlapping, different ways. You try to merge A while you
are at B and see conflicts in these two files.
Let's say you resolved frotz; the contents in frotz is in a desired
shape, i.e you have the changes you want from the line led to A and the
other line led to B. But you haven't resolved xyzzy yet.
You seem to want to make this half-resolved state as a commit. First
question: what contents would you want to commit for xyzzy?
If you commit the contents from B (because you started from it), then it
should not be recorded as a proper merge. If you did so, merging that
back to A would obliterate all the work done up to A to file xyzzy:
o---o---A...X
/ \ .
---o---o---B---*
because merge base of A and * (I am marking it differently because such
an incomplete merge should not be made) is A, so the result (X) will be
the half-merge * itself (fast forward). That's not a merge as it is not
better than A -- you discarded improvements made to xyzzy by people who
built up to A.
This is inherent to what a merge is. With proper understanding of what
a merge is, you would not feel this limiting at all.
Having said that, I think something like the following _could_ be done,
although I do not know if it makes much sense.
(1) Try merge, see it conflict, resolve only a part of it, and record
the result as "WIP to merge in A". Do not record it as a merge, as
it is not. diff between B and M will contain a squash merge of A on
top of B minus the changes to the path xyzzy.
o---o---A
/
---o---o---B---M
(2) Fix up the conflicts in xyzzy to resolve the conflicts fully, and
record the result as "Final merge of A into B". This should be
recorded as a merge, as the result is "keeping changes done on both
branches to come up with something better than either of them."
o---o---A---,
/ \
---o---o---B---M---N
If you look at the topology a bit differently, the above actually makes
some sense:
.---o---o---A
/ \
---o---o---B---M---N
That is, instead of merging A into B, you made "preparatory changes" to
branch B in order to make it easier to merge A. That's what the commit
M is about.
Then you merge A on top of M. In reality, because the difference
between B to M contains most of the squash merge of A into B, such a
merge N will contain many accidental clean merges. But in git,
accidental clean merges are not a problem (people can apply the same
patch to their trees and later their branches can be merged).
But "git commit" after a conflicted merge will always create a merge,
and there is no canned option to do multi-step merge like the above.
You can still do that by hand, by doing something like:
$ git merge --squash A
$ resolve only partly
$ git commit -m 'Prepare to merge A'
$ git reset --hard
$ git merge A
$ resolve the rest
$ git commit -m 'Fully merged A'
For such a multi-step merge to make sense, the change between B---M
should make sense by itself for people who have to read such a history
later. Such a half-a-squash-merge may probably not make sense by itself
in most cases, so I suspect the above workflow would not be useful in
general.
next prev parent reply other threads:[~2007-11-28 20:09 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-28 15:48 can't commit files that have been git add'ed because "fatal: you need to resolve your current index first" Bill Priest
2007-11-28 15:53 ` Jakub Narebski
2007-11-28 20:08 ` Junio C Hamano [this message]
[not found] <251604.8861.qm@web55007.mail.re4.yahoo.com>
2007-11-28 16:55 ` Jakub Narebski
[not found] <993937.9873.qm@web55013.mail.re4.yahoo.com>
2007-11-28 18:11 ` Jakub Narebski
-- strict thread matches above, loose matches on Subject: below --
2007-11-29 4:10 Bill Priest
2007-11-30 16:32 Bill Priest
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7v63zm5e0n.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=priestwilliaml@yahoo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).