从子文件夹Git多个子项目? [英] Git multiple sub projects from sub folders?
问题描述
我有很多项目想放在GitHub.com上。所有这些项目都在我的本地Git存储库中。我只有一个存储库,但是对于每个项目,我希望有一个GitHub项目。这样,错误可以由项目组织。
我如何设置它以便管理起来并不困难?我是否需要重做我的存储库布局,并为每个项目在本地创建新的git存储库?这将涉及到真正的时间,我可能会失去Git的历史。
Walter
根据您的仓库组织方式,您可以使用 git filter-branch
为每个项目创建一个新仓库,为每个项目保留历史记录<假设您目前的回购结构如下所示:
repo /
project1 /
project1-file
project2 /
project2-file
project3 /
project3-file
您可以先将 git filter-branch
会 )。然后,在您的克隆回购中,您可以使用 git filter-branch
在 project1的根目录下创建一个新的回购(包含所有旧的历史记录)
:
$ git filter-branch --subdirectory-filter project1 HEAD
现在,您的回购将如下所示:
repo /
project1-file
在旧回购库中存储在 project1 /
下的所有文件的历史记录。
为每个项目重复该步骤,现在您将拥有三个独立回购站,并拥有所有相关项目的历史记录。
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 like to have 1 GitHub project. That way, bugs can be organized by the project.
How can I set this up so that it isn't that difficult to manage? Do I need to redo my repository layout and create new git repositories locally for each project? That would be really time involved and I might be losing the Git history.
Walter
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.
这篇关于从子文件夹Git多个子项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!