Git multiple sub projects from sub folders?

后端 未结 2 1982
没有蜡笔的小新
没有蜡笔的小新 2021-02-13 21:07

I have multiple projects that I\'d like to put up onto GitHub.com. All of these projects are in my local Git repository. I have just one repository, but for each project, I\'d

2条回答
  •  长情又很酷
    2021-02-13 21:42

    Depending on how your repo is organized, you can use git filter-branch to create a new repo for each project, retaining history for each individual project only.

    Assuming your current repo structure is like this:

    repo/
      project1/
        project1-file
      project2/
        project2-file
      project3/
        project3-file
    

    You can first clone your repo (git filter-branch will remove files and their history, so clone your original repo first). Then, in your cloned repo, you can use git filter-branch to create a new repo (with all the old history) at the root of project1:

    $ git filter-branch --subdirectory-filter project1 HEAD
    

    Now, your repo will look like the following:

    repo/
      project1-file
    

    And it will still contain the history for all files that were stored under project1/ in the old repo.

    Repeat that step for each project, and you will now have three independent repos, with all the history for their relevant projects.

提交回复
热议问题