git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: how to combine two clones in a collection

From
Brian Gernhardt <benji@silverinsanity.com>
Date
Jul 10, 2007, 18:27 UTC
Message-ID
<72218C10-EE5E-4CD9-B5DE-DFEC40EBEF27@silverinsanity.com>
In-Reply-To
<20070710174543.GA16054@piper.oerlikon.madduck.net>
On Jul 10, 2007, at 1:45 PM, martin f krafft wrote:
Show 7 quoted lines
> I wonder how to create a project with two completely independent
> branches which have no common ancestry. I don't think it's possible.
> One needs a throwaway branch to create the first commit, then branch
> each of the two branches off that, then delete the throwaya branch
> (or keep it around).
>
> But this is getting academic now...
But interesting.

What you describe won't create two independent branches. They'll share the root commit. I think what you have do is create the first branch as normal, then clear out the working copy (be sure not to delete .git) and do the commit manually. I believe it goes something like this:

   git init
   # Create files for master
   git add .
   git commit
   rm -rf * .git/index
   # Create files for second branch
   git add .
   tree=$(git write-tree)
   # Edit commit message into some file (commit-msg here)
   commit=$(git commit-tree $tree < commit-msg)
   git update-ref refs/branches/independent $commit

The important bits are to be sure to remove the index so you don't commit the wrong files and the last four lines that do the heavy lifting. You could also create the branch in a second repository and pull it from there into the first (probably simpler), or perhaps trick git-commit into thinking there isn't any commits yet (remove the index and HEAD perhaps?).

~~ Brian
Previous: martin f krafftNext: Kalle Pokki
Message 9 of 16 in “how to combine two clones in a collection”
  1. martin f krafftJul 9, 2007
  2. Linus TorvaldsJul 10, 2007
  3. martin f krafftJul 10, 2007
  4. Junio C HamanoJul 10, 2007
  5. martin f krafftJul 10, 2007
  6. Martin LanghoffJul 10, 2007
  7. Linus TorvaldsJul 10, 2007
  8. martin f krafftJul 10, 2007
  9. Brian GernhardtJul 10, 2007
  10. Kalle PokkiJul 10, 2007
  11. Brian GernhardtJul 10, 2007
  12. Robin RosenbergJul 10, 2007
  13. martin f krafftJul 11, 2007
  14. Johannes SchindelinJul 11, 2007
  15. martin f krafftJul 11, 2007
  16. Jakub NarebskiJul 11, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.