Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export subtree in Git with history

I have a folder in my Git repository that I'd like to move out in to its own repository. Is it possible to move the history of that folder along with the folder?

I've previously been doing just a git rm -r --cached subfolder/ and then git init on the subfolder. However, the history is not imported in to the new repository.

like image 587
matpie Avatar asked Nov 02 '09 18:11

matpie


People also ask

Does git archive include history?

Use Git Archive for Files The available list of formats can be retrieved with the git archive --list command. But the Git archive command includes only the files, not the history of those files.

What can you do with git archive?

By default, git archive will stream the archive output to the ephemeral stdout stream. You will need to capture this output stream to a permanent file. You can specify a permanent file by using git archives output option or using the operating systems stdout redirection.


1 Answers

Quoting an example from git-filter-branch(1)

To rewrite the repository to look as if foodir/ has been its project root, and discard all other history:

git filter-branch --subdirectory-filter foodir -- --all 

Thus you can, e.g., turn a library subdirectory into a repository of its own. Note the -- that separates filter-branch options from revision options, and the --all to rewrite all branches and tags.

like image 143
jamessan Avatar answered Oct 12 '22 01:10

jamessan