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

Re: How to merge by subtree while preserving history?

From
Miklos Vajna <vmiklos@frugalware.org>
Date
Mar 27, 2009, 07:38 UTC
Message-ID
<20090327073847.GE27459@genesis.frugalware.org>
In-Reply-To
<A5C2B218-4E4F-4C05-959D-5B6E9C619DDB@gmail.com>
On Thu, Mar 26, 2009 at 06:59:51PM -0400, David Reitter <david.reitter@gmail.com> wrote:
Show 6 quoted lines
> I have two separately developed projects (foo, bar) which I'd like to  
> merge; the contents of foo should, initially, go in a subdirectory of  
> bar.
> 
> I'm aware of two methods:  moving (renaming) everything within foo  
> into foo-dir, and then just pulling foo into bar.
The result of the two methods are the same.
Show 7 quoted lines
> This works beautifully, except that the big rename causes havoc w.r.t.  
> to the files histories, i.e. git-log needs a "--follow" argument now,  
> and "diff-tree" can't track changes when given the new file name.  No  
> good.
> 
> I've also tried the method described in [1], but it seems that all  
> history is lost here (the text could point this out..)
Of course it is not lost. :)
Example:
commit f8c62880ef22b74ea6df47bb349ff0743d2a93f9
Merge: f474c52... 52b8ea9...
Author: Junio C Hamano <gitster@pobox.com>
Date:   Sun Mar 1 22:20:52 2009 -0800
    Merge git://git.kernel.org/pub/scm/gitk/gitk
Now do a 'git log f474c52..52b8ea9' and you'll see the merged commits.

But you are right about that 'git log -- path' will find the merge commits only (which is right, as the tree objects are not modified when merging, just the resulting tree has the original tree in a subdirectory).

If this is a one-time operation then I would just use git filter-branch to move the code to a subdir.

Previous: David ReitterNext: David Reitter
Message 2 of 4 in “How to merge by subtree while preserving history?”
  1. David ReitterMar 26, 2009
  2. Miklos VajnaMar 27, 2009
  3. David ReitterMar 27, 2009
  4. Junio C HamanoMar 27, 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.