threads / discuss / 22480

How can I create a commit without a parent?

Subject: How can I create a commit without a parent?

## tl;dr

5 messages between Feb 2, 2010 and Feb 2, 2010.

replies: 4people: 4as markdown or json

Ron Garret· Feb 2, 2010, 08:00 UTC · lore

SLSIA. git commit-tree insists on having at least one parent commit at the command line. From reverse-engineering it seems like I could do it by setting .git/HEAD to 'ref: refs/heads/some-nonexistent-branch' but mucking with HEAD directly like that feels kinda scary.

Thanks, rg

Junio C Hamano· Feb 2, 2010, 08:05 UTC · re: Ron Garret · lore

Re: How can I create a commit without a parent?

Ron Garret <ron1@flownet.com> writes:
> git commit-tree insists on having at least one parent commit at 
> the command line.

Incorrect. "git commit" might but "git commit-tree" does. Perhaps you are forgetting that the first object name is a tree to be wrapped.

A short answer is that you don't create a root commit twice in a single repository, period. Your repository _may_ be end up with more than one root but that typically is due to you fetching unrelated histories from different repositories, each created its own root.

Ron Garret· Feb 2, 2010, 08:19 UTC · re: Junio C Hamano · lore

Re: How can I create a commit without a parent?

In article <7vwryw6p16.fsf@alter.siamese.dyndns.org>,
 Junio C Hamano <gitster@pobox.com> wrote:
Show 7 quoted lines
> Ron Garret <ron1@flownet.com> writes:
> 
> > git commit-tree insists on having at least one parent commit at 
> > the command line.
> 
> Incorrect.  "git commit" might but "git commit-tree" does.  Perhaps you
> are forgetting that the first object name is a tree to be wrapped.
No, I didn't forget that.  I forgot to omit the -p flag.  Doh!
> A short answer is that you don't create a root commit twice in a single
> repository, period.

Why not? I could easily create an empty root commit and multiple branches off that. (Maybe that's a better way to go.) What would be the difference?

rg
Jakub Narebski· Feb 2, 2010, 15:02 UTC · re: Ron Garret · lore

Re: How can I create a commit without a parent?

Ron Garret <ron1@flownet.com> writes:
> SLSIA.  git commit-tree insists on having at least one parent commit at 
> the command line.  From reverse-engineering it seems like I could do it 
> by setting .git/HEAD to 'ref: refs/heads/some-nonexistent-branch' but 
> mucking with HEAD directly like that feels kinda scary.

You have git-symbolic-ref to set HEAD directly (don't forget to remove index).

Or you can set up / initialize separate (new) repository, create commit there and then pull this new repository into current one.

P.S. Creating new root (parentless) commit isn't something that you do on purpose, usually.

-- 
Jakub Narebski
Poland
ShadeHawk on #git
Jay Soffian· Feb 2, 2010, 16:40 UTC · re: Ron Garret · lore

Re: How can I create a commit without a parent?

On Tue, Feb 2, 2010 at 3:00 AM, Ron Garret <ron1@flownet.com> wrote:
> SLSIA.  git commit-tree insists on having at least one parent commit at
> the command line.  From reverse-engineering it seems like I could do it
> by setting .git/HEAD to 'ref: refs/heads/some-nonexistent-branch' but
> mucking with HEAD directly like that feels kinda scary.

I guess you're looking to do it with plumbing, but with porcelain the way I'd do it is:

$ git init foo $ git init bar $ cd bar $ git commit --allow-empty -m "empty bar root commit" $ cd ../foo $ git commit --allow-empty -m "empty foo root commit" $ git fetch ../bar master:bar

j.

← back to recent threads