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

Re: Move some files, with all history, from one project into a new one

From
Jeff King <peff@peff.net>
Date
Apr 15, 2020, 15:11 UTC
Message-ID
<20200415151128.GA2464307@coredump.intra.peff.net>
In-Reply-To
<AM0PR02MB3715F9566BD9FEFAF832F0749CDB0@AM0PR02MB3715.eurprd02.prod.outlook.com>
On Wed, Apr 15, 2020 at 08:31:35AM +0000, Kerry, Richard wrote:
> I would like to move some files, from the project in which they have
> always resided into  a new project.  I would like to keep all their
> history.  I don't want to waste space by also moving the rest of the
> old project's history, or historical file contents.

Try git-filter-branch's --subdirectory repository, which is designed to do exactly this.

Or the much newer (and faster) git-filter-repo:
  https://github.com/newren/git-filter-repo
Show 5 quoted lines
> Do I create a new branch, then delete the rest of main-system leaving
> only what I want?  Surely if I do that then I would end up with all
> the main-system file data within the new repo, which would expand its
> size.  Is there a recommended way to extract certain files with their
> histories?

Correct; just deleting files and creating a new commit will still carry them in the history. You have to rewrite the old commits.

-Peff
Previous: Kerry, RichardNext: Taylor Blau
Message 2 of 5 in “Move some files, with all history, from one project into a new one”
  1. Kerry, RichardApr 15, 2020
  2. Jeff KingApr 15, 2020
  3. Taylor BlauApr 15, 2020
  4. Elijah NewrenApr 16, 2020
  5. Kerry, RichardApr 17, 2020

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.