How to extract a git subdirectory and make a submodule out of it?

前端 未结 5 812
别跟我提以往
别跟我提以往 2020-11-27 09:07

I started a project some months ago and stored everything within a main directory. In my main directory \"Project\" there are several subdirectories containing different thi

5条回答
  •  鱼传尺愫
    2020-11-27 10:01

    Checkout git filter-branch.

    The Examples section of the man page shows how to extract a sub-directory into it's own project while keeping all of it's history and discarding history of other files/directories (just what you're looking for).

    To rewrite the repository to look as if foodir/ had 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.

提交回复
热议问题