From: Junio C Hamano <junkio@cox.net>
To: linux@horizon.com
Cc: git@vger.kernel.org
Subject: Re: git-name-rev off-by-one bug
Date: Mon, 28 Nov 2005 21:54:05 -0800 [thread overview]
Message-ID: <7vhd9wngn6.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: 20051128234256.1508.qmail@science.horizon.com
linux@horizon.com writes:
> (Being able to back up the object database is obviously simple, but what
> happens if the index holds HEAD+1, the working directory holds HEAD+2,
> and I try to mere the latest changes from origin? Are either HEAD+1 or
> HEAD+2 in danger of being lost, or will checking them in later overwrite
> the merge, or what?)
Thanks for the complaints. No sarcasm intended. Yours is
exactly the kind of message we (people who've been around here
for too long) need to hear.
Although the technical details are hidden in the documentation
which needs reorganization to make them easier to find [*1*] as
you point out, the guiding principle for merge is quite simple.
To the git barebone Porcelain layer (things that start with
git-*, not with cg-*) [*2*], a merge is always between the
current HEAD and one or more remote branch heads, and the index
file must exactly match the tree of HEAD commit (i.e. the
contents of the last commit) when it happens. In other words,
"git-diff --cached HEAD" must report no changes [*3*]. So
HEAD+1 must be HEAD in your above notation, or merge will refuse
to do any harm to your repository (that is, it may fetch the
objects from remote, and it may even update the local branch
used to keep track of the remote branch with "git pull remote
rbranch:lbranch", but your working tree, .git/HEAD pointer and
index file are left intact).
You may have local modifications in the working tree files. In
other words, "git-diff" is allowed to report changes (the
difference between HEAD+2 and HEAD+1 in your notation).
However, the merge uses your working tree as the working area,
and in order to prevent the merge operation from losing such
changes, it makes sure that they do not interfere with the
merge. Those complex tables in read-tree documentation define
what it means for a path to "interfere with the merge". And if
your local modifications interfere with the merge, again, it
stops before touching anything.
So in the above two "failed merge" case, you do not have to
worry about lossage of data --- you simply were not ready to do
a merge, so no merge happened at all. You may want to finish
whatever you were in the middle of doing, and retry the same
pull after you are done and ready.
When things cleanly merge, these things happen:
(1) the results are updated both in the index file and in your
working tree,
(2) index file is written out as a tree,
(3) the tree gets committed, and
(4) the HEAD pointer gets advanced.
Because of (2), we require that the original state of the index
file to match exactly the current HEAD commit; otherwise we will
write out your local changes already registered in your index
file (the difference between HEAD+1 and HEAD in your notation)
along with the merge result, which is not good. Because (1)
involves only the paths different between your branch and the
remote branch you are pulling from during the merge (which is
typically a fraction of the whole tree), you can have local
modifications in your working tree as long as they do not
overlap with what the merge updates.
When there are conflicts, these things happen:
(0) HEAD stays the same.
(1) Cleanly merged paths are updated both in the index file and
in your working tree.
(2) For conflicting paths, the index file records the version
from HEAD. The working tree files have the result of
"merge" program; i.e. 3-way merge result with familiar
conflict markers <<< === >>>.
(3) No other changes are done. In particular, the local
modifications you had before you started merge will stay the
same and the index entries for them stay as they were,
i.e. matching HEAD.
After seeing a conflict, you can do two things:
* Decide not to merge. The only clean-up you need are to reset
the index file to the HEAD commit to reverse (1) and to clean
up working tree changes made by (1) and (2); "git-reset" can
be used for this.
* Resolve the conflicts. "git-diff" would report only the
conflicting paths because of the above (1) and (2). Edit the
working tree files into a desirable shape, git-update-index
them, to make the index file contain what the merge result
should be, and run "git-commit" to commit the result.
[Footnotes]
*1* It is a shame that the most comprehensive definition of
3-way read-tree semantics is in t/t1000-read-tree-m-3way.sh test
script.
*2* Cogito (things that start with cg-*) seems to try to be
cleverer. Pasky might want to brag about the rules in Cogito
land.
*3* This is a bit of lie. In certain special cases, your index
are allowed to be different from the tree of HEAD commit;
basically your index entries are allowed to match the result of
trivial merge already (e.g. you received the same patch from
external source to produce the same result as what you are
merging). For example, if a path did not exist in the common
ancestor and your head commit but exists in the tree you are
merging into your repository, and if you already happen to have
that path exactly in your index, the merge does not have to
fail. This is case #2 in the 3-way read-tree table in t/t1000.
next prev parent reply other threads:[~2005-11-29 5:54 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-11-28 23:42 git-name-rev off-by-one bug linux
2005-11-29 5:54 ` Junio C Hamano [this message]
2005-11-29 8:05 ` linux
2005-11-29 9:29 ` Junio C Hamano
2005-11-30 8:37 ` Junio C Hamano
2005-11-29 10:31 ` Petr Baudis
2005-11-29 18:46 ` Junio C Hamano
2005-12-04 21:34 ` Petr Baudis
2005-12-08 6:34 ` as promised, docs: git for the confused linux
2005-12-08 21:53 ` Junio C Hamano
2005-12-08 22:02 ` H. Peter Anvin
2005-12-09 0:47 ` Alan Chandler
2005-12-09 1:45 ` Petr Baudis
2005-12-09 1:19 ` Josef Weidendorfer
2005-11-29 21:40 ` git-name-rev off-by-one bug linux
2005-11-29 23:14 ` Junio C Hamano
2005-11-30 0:15 ` linux
2005-11-30 0:53 ` Junio C Hamano
2005-11-30 1:27 ` Junio C Hamano
2005-11-30 1:51 ` Linus Torvalds
2005-11-30 2:06 ` Junio C Hamano
2005-11-30 2:33 ` Junio C Hamano
2005-11-30 3:12 ` Linus Torvalds
2005-11-30 5:06 ` Linus Torvalds
2005-11-30 5:51 ` Junio C Hamano
2005-11-30 6:11 ` Junio C Hamano
2005-11-30 16:13 ` Linus Torvalds
2005-11-30 16:08 ` Linus Torvalds
2005-12-02 8:25 ` Junio C Hamano
2005-12-02 9:14 ` [PATCH] merge-one-file: make sure we create the merged file Junio C Hamano
2005-12-02 9:15 ` [PATCH] merge-one-file: make sure we do not mismerge symbolic links Junio C Hamano
2005-12-02 9:16 ` [PATCH] git-merge documentation: conflicting merge leaves higher stages in index Junio C Hamano
2005-11-30 6:09 ` git-name-rev off-by-one bug linux
2005-11-30 6:39 ` Junio C Hamano
2005-11-30 13:10 ` More merge questions linux
2005-11-30 18:37 ` Daniel Barkalow
2005-11-30 20:23 ` Junio C Hamano
2005-12-02 9:19 ` More merge questions (why doesn't this work?) linux
2005-12-02 10:12 ` Junio C Hamano
2005-12-02 13:09 ` Sven Verdoolaege
2005-12-02 20:32 ` Junio C Hamano
2005-12-05 15:01 ` Sven Verdoolaege
2005-12-02 11:37 ` linux
2005-12-02 20:31 ` Junio C Hamano
2005-12-02 21:32 ` linux
2005-12-02 22:00 ` Junio C Hamano
2005-12-02 22:12 ` Linus Torvalds
2005-12-02 23:14 ` linux
2005-12-02 21:56 ` More merge questions linux
2005-11-30 16:12 ` git-name-rev off-by-one bug Linus Torvalds
2005-11-30 7:18 ` Junio C Hamano
2005-11-30 9:05 ` Junio C Hamano
2005-11-30 9:42 ` Junio C Hamano
2005-11-30 3:15 ` linux
2005-11-30 18:11 ` Daniel Barkalow
2005-11-30 17:46 ` Daniel Barkalow
2005-11-30 20:05 ` Junio C Hamano
2005-11-30 21:06 ` Daniel Barkalow
2005-11-30 22:00 ` Junio C Hamano
2005-11-30 23:12 ` Daniel Barkalow
2005-12-01 7:46 ` Junio C Hamano
2005-12-01 10:14 ` Junio C Hamano
2005-12-01 21:50 ` Petr Baudis
2005-12-01 21:53 ` Randal L. Schwartz
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=7vhd9wngn6.fsf@assigned-by-dhcp.cox.net \
--to=junkio@cox.net \
--cc=git@vger.kernel.org \
--cc=linux@horizon.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).