简体   繁体   English

将目录移动到另一个git存储库,同时保留相关历史记录

[英]Moving a directory to another git repository while retaining relevant history

I have a git repository containing multiple components, each in their own directory. 我有一个git存储库,其中包含多个组件,每个组件都位于各自的目录中。 I now want to put each component in its own git repo. 我现在想将每个组件放入其自己的git repo中。 A requirement here is that the git history is not lost, so git blame still works. 这里的要求是git历史记录不会丢失,因此git blame仍然有效。 I'm looking for a way to do this and not have unrelated git history. 我正在寻找一种做到这一点并且没有无关的git历史记录的方法。 There are two reasons for this: I do not want the repo history to be cluttered with changes to code not part of the component and I like the commit count and other things in the history to be reasonably accurate. 这样做的原因有两个:我不希望回购历史记录因不属于组件一部分的代码更改而混乱不堪,并且我希望历史记录中的提交计数和其他事情都相当准确。

I already looked at this helpful post which goes in the right direction. 我已经看过这篇朝着正确方向发展的有用文章 It however does not remove pointless commits altogether (so now there are a lot of null commits in the history). 但是,它不会完全删除无意义的提交(因此,历史记录中现在有很多空提交)。 It also does not retain history for files that got moved from some other component in the past (ion case that component is excluded), or even if they where touched in a commit that also touched files in ignored components. 它也不会保留过去从其他组件移出的文件的历史记录(即使该组件被排除在外),即使提交中碰到的文件也碰到了被忽略组件中的文件。

Is there a better way of doing this? 有更好的方法吗?

git filter-branch has a specialized mode for reducing a repository to a subdir. git filter-branch具有专门的模式,可将存储库简化为子目录。 Check out the option --subdirectory-filter . --subdirectory-filter--subdirectory-filter选项。 It should get rid of irrelevant commits automatically, and it moves the contents of the subdir to the top level of the repo. 它应该自动删除不相关的提交,并将子目录的内容移到存储库的顶层。

However, it does not track/follow file renames. 但是,它不跟踪/跟随文件重命名。 You're looking at a lot of manual work if you want that. 如果需要的话,您正在看很多手工工作。 After all, you'd have to include changes to the files in their old location but also rewrite the paths to the post-rename location. 毕竟,您必须在文件的旧位置中包含对文件的更改,而且还必须将路径重写为重命名后的位置。 We don't have anything that ships with git that does this. 我们没有git附带的任何工具来做到这一点。

暂无
暂无

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

相关问题 git 将目录移动到另一个存储库,同时保留历史记录 - git move directory to another repository while keeping the history 将GIT存储库(和提交历史记录)移动到当前为空的另一个存储库 - Moving GIT repository (and commit history) to another repository currently empty 将git存储库历史记录的一部分移动到另一个存储库中 - Moving part of a git repository’s history into another repository 将 Git 存储库的一部分移动到另一个存储库以保留历史记录 - Moving part of Git repository to another repository preserving history 将 Git 存储库内容移动到另一个存储库以保留历史记录 - Moving Git repository content to another repository preserving history 如何在将少量文件从一个GIT存储库移动到另一个存储库时保留预重命名历史记录? - How to retain pre-rename history while moving few files from one GIT repository to another? 在移动GIT存储库时保留GIT提交的历史记录 - Preserving history of GIT commits while moving a GIT repository 将git存储库作为子文件夹移动到另一个存储库,同时保留历史记录 - Move a git repository to another repository as a subfolder while keeping history 如何在保留历史记录和文件结构的同时将git存储库的一部分提取到自己的存储库中? - How can I extract a portion of a git repository into it's own repo while retaining history and file structure? git:将一个存储库的历史记录复制(复制)到另一个存储库的目录中 - git: copy (cherry-pick) history of one repository into a directory of another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM