Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git subtree split two directories

I've been following this excellent answer to extract a subdirectory of my git repository into its own repository, while retaining the complete history.

My repository looks like:

src/
    http/
    math/
tests/
    http/
    math/

I want to create a new branch that only contains the src/math and tests/math directories.

If I run the following command:

git subtree split -P src/math -b math

It creates a branch that contains the contents of the src/math directory, but discards the src/math/ prefix.

If I try the same command with two directories:

git subtree split -P src/math -P tests/math -b math

It only extracts the contents of tests/math, ignoring src/math, and also discarding the tests/math prefix.

To summarize, I would like my final repository to look like:

src/
    math/
tests/
    math/

That is, keeping the original directory structure but discarding everything that's not explicitly mentioned in the command-line.

How can I do that?

like image 422
BenMorel Avatar asked Aug 29 '14 18:08

BenMorel


1 Answers

Use git-filter-repo This is not part of git as of version 2.25. This requires Python3 (>=3.5) and git 2.22.0

git filter-repo --path src/math --path tests/math 

For my repo that contained ~12000 commits git-filter-branch took more than 24 hours and git-filter-repo took less than a minute.

like image 67
Kishore A Avatar answered Oct 04 '22 08:10

Kishore A