Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does a mercurial revision with no parent mean?

Tags:

mercurial

I have a Mercurial repository that is in a strange state now. This is what it looks like in TortoiseHG:

Hg graph

I didn't think this would be possible. Revision 54 has a parent of "-1 (000000000000)" (i.e. nothing). There's clearly something I don't understand yet about Mercurial, can anyone let me know what this means - and what must have happened for it to get into this state. As far as I know, it's only had stuff pushed and pulled from it - and nobody has been using any wacky extensions.

Revisions 54 and 55 were just adding tags, but if I 'update -C' to revision 54 I end up with ONLY the .hgtags file.

I've made a clone from revision 53 to fix this. But I'd rather understand what happened here, so I can avoid it happening again.

like image 840
Wilka Avatar asked May 19 '10 09:05

Wilka


People also ask

How does Mercurial work?

Mercurial groups related changes to multiple files into single atomic changesets, which are revisions of the whole project. These each get a sequential revision number. Because Mercurial allows distributed parallel development, these revision numbers may disagree between users.

What is Mercurial changeset?

(for a short intro of the basic concepts of Mercurial, see UnderstandingMercurial) A changeset (sometimes abbreviated "cset") is an atomic collection of changes to files in a repository. It contains all recorded local modification that lead to a new revision of the repository.

What is HG tip?

Use the hg heads command to list the heads of the current repository. The tip is the changeset added to the repository most recently. If you have just made a commit, that commit will be the tip. Alternately, if you have just pulled from another repository, the tip of that repository becomes the new tip.

What is a head in mercurial?

A head is a changeset with no child changesets. The tip is the most recently changed head. Other heads are recent pulls into a repository that have not yet been merged. If you have just made a commit, that commit will be the tip.


2 Answers

When you look at the definition of a changeset, you see:

Each changeset has zero, one or two parent changesets:

  • It has two parent changesets, if the commit was a merge.
  • It has no parent, if the changeset is a root in the repository.
    There may be multiple roots in a repository (normally, there is only one), each representing the start of a branch.

"Updating" back to a changeset which already has a child, changing files and then committing creates a new child changeset, thus starting a new branch. Branches can be named.

So maybe this is what you did:

  • updating back to 53 (which had already a child '54' of its own back then)
  • changing files
  • committing, thus starting a new branch from 54, with no parent
    (that would make a second commit with the same parent)

or:

  • comitting 53 with a --close-branch option,
  • potentially a new commit (without switching back to another branch) might begin a new one

Ry4an (an actual Mercurial specialist ;) ) chimes in and comments:

--close-branch doesn't do anything except hide a branch from a list, and it's undone next time you commit on that branch. It won't create multiple roots.

VonC is right in his diagnosis, multiple heads.
But no combination of 'update' and 'commit' will get you into that state.
To end up with multiple roots one usually has done a 'hg pull' from repo and used --force to override an "unrelated repositories" warning.


("no parent", meaning the parent ids are set to 00000, see "behind the scene":

alt text
(source: red-bean.com)
)

like image 56
VonC Avatar answered Sep 22 '22 03:09

VonC


Another way to see this is if you did hg update null after committing rev. 53. For example, consider this sequence:

hg init foo
# create some files
hg addremove
hg commit -m "Revision 0"
# edit, edit, edit
hg commit -m "Revision 1"
hg update null
hg tag -m "Create tag v1.0.0.0" "v1.0.0.0"

At this point, hg log will show revision 2's parent as -1:0000000000. Since hg update null clears out the working directory, the only file in it would be .hgtags (just like you were seeing).

Did you have other tags prior to rev. 53? If my suspicion is correct, they would not be present in your rev. 54 .hgtags.

like image 38
Niall C. Avatar answered Sep 24 '22 03:09

Niall C.