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

Re: combine git repo historically

From
Jakub Narebski <jnareb@gmail.com>
Date
Oct 11, 2009, 08:48 UTC
Message-ID
<m31vlagvtw.fsf@localhost.localdomain>
In-Reply-To
<200910110436.52653.chriscool@tuxfamily.org>
Christian Couder <chriscool@tuxfamily.org> writes:
> On Saturday 10 October 2009, bill lam wrote:
Show 23 quoted lines
> > Christian Couder also mentioned the git-replace command, how to stitch
> > with it?
> 
> First you need to create a commit that will replace commit N, let's call it 
> N' and after that you can use "git replace N N'". So the complex part is to 
> create N'.
> 
> You want N' to have the same content as N but to have M as parent. So you 
> could do something like the following:
> 
> (We suppose that commits A to M are in branch1 and that you are in the root 
> directory of your repo2 working directory.)
> 
> $ git checkout -b repo1-branch1 remote/repo1/branch1
> $ git checkout N -- .
> $ export GIT_AUTHOR_NAME=<author name of commit N>
> $ export GIT_AUTHOR_EMAIL=<author email of commit N>
> $ export GIT_AUTHOR_DATE=<date of commit N>
> $ git commit -a
> 
> And then use the commit message from commit N, and maybe also say in the 
> commit message that it is replacement commit made to link repo1 with repo2 
> or something like that.

I think simpler solution would be to use plumbing for that. First save commit to be replaced in a (text) file:

 $ git cat-file commit N > COMMIT_N

If you want to edit only commit message and perhaps parentage (like I think in this case), you need to simply edit COMMIT_N file, and modify (or add) 'parent' header(s), which is between 'tree' and 'author' header.

Then put modified commit in repository object database
 $ git hash-object -t commit -w COMMIT_N
 
Show 7 quoted lines
> At this step you have created N' and you should make sure that it is exactly 
> what you want. It should point to the same tree as N, it should have M as 
> parent, ...
> 
> If everything is ok then you can use:
> 
> $ git replace N HEAD
And then do
 $ git replace N NEW_N
where N is _SHA-1_ of original comit ("git rev-parse --verify N^0"),
and NEW_N is SHA-1 of replacement commit, as written by git-hash-object.
 
> And you should be done.
But I haven't tested this. YMMV.

See also my answer here: http://stackoverflow.com/questions/1220557/how-do-i-prepend-history-to-a-git-repo/1547490#1547490

-- 
Jakub Narebski
Poland
ShadeHawk on #git
Previous: Christian CouderNext: Johannes Sixt
Message 8 of 12 in “combine git repo historically”
  1. bill lamOct 9, 2009
  2. Johannes SixtOct 9, 2009
  3. Christian CouderOct 9, 2009
  4. bill lamOct 10, 2009
  5. Christian CouderOct 11, 2009
  6. bill lamOct 11, 2009
  7. Christian CouderOct 11, 2009
  8. Jakub NarebskiOct 11, 2009
  9. Johannes SixtOct 11, 2009
  10. Christian CouderOct 11, 2009
  11. Jakub NarebskiOct 11, 2009
  12. Andreas SchwabOct 11, 2009

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.