简体   繁体   English

从前一个提交创建一个git存储库

[英]Create a git repository from commits of a previous one

I was part of a project that involved creating a redmine plugin with lot of features. 我是一个涉及创建具有许多功能的redmine插件的项目的一部分。

Now I want to take some of the features and turn them into individual plugins. 现在我想采取一些功能,并将它们变成单独的插件。 For that I will create one separate git repository for each. 为此,我将为每个创建一个单独的git存储库。

In that git repository I would like to have the intact history from the original git repository with only the files related to that feature. 在那个git存储库中,我希望从原始git存储库中获得完整的历史记录,只包含与该功能相关的文件。

Should I had the older repository as a remote and go through every commit manually, finding the ones that interest me, and committing them to the new repository? 我是否应该将旧存储库作为远程存储器并手动完成每个提交,找到我感兴趣的存储库,并将它们提交到新的存储库?

Or is there another (more practical) way to do it? 或者还有另一种(更实际的)方法吗?

The workflow on the old git repository was: 旧git存储库上的工作流程是:

  • There was only the master branch; 只有主分支;

  • Every time a milestone was completed it was committed and pushed to the remote; 每当里程碑完成,它就会被提交并推送到遥控器;

Look at git-filter-branch(1) which is Git's Swiss-army knife for automated rewriting of history and it certainly allows you to keep all commits touching a defined set of files (and drop everything else). 看看git-filter-branch(1) ,它是Git的瑞士军刀,用于自动重写历史记录,它当然允许你保持所有提交触及一组已定义的文件(并丢弃其他所有文件)。

How to use it in detail, depends on your actual repository. 如何详细使用它取决于您的实际存储库。 If, for example, all the files you want to keep are already neatly contained in a subdirectory (say, foobar ), then the following would be sufficient: 例如,如果您要保留的所有文件已经整齐地包含在子目录中(例如, foobar ),那么以下就足够了:

git filter-branch --subdirectory-filter foobar --prune-empty -- --all

As an alternative, you could use the following to remove all files but the ones you want to keep from your repository: 作为替代方法,您可以使用以下内容删除所有文件,但要删除存储库中的文件:

git filter-branch --tree-filter 'rm -f filename1 pattern2.*' --prune-empty -- --all

Rather than rewriting history to extract just the files you're interested in, you could keep the original history — which provides the context for all the changes — and add a new commit which just deletes all the files you aren't interested in. 您可以保留原始历史记录(它提供所有更改的上下文),而不是重写历史记录以仅提取您感兴趣的文件,并添加新提交,只删除您感兴趣的所有文件。

Clone the original repository, then make a branch for each plugin, and on each branch, delete anything that isn't relevant to that plugin. 克隆原始存储库,然后为每个插件创建一个分支,并在每个分支上删除与该插件无关的任何内容。 That way, all your plugins have history that traces back to their common origins. 这样,你所有的插件都有追溯到它们共同起源的历史。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM