使用 git filter-repo 清理 git 历史记录

问题描述 投票:0回答:1

我有一个曾经是 monorepo 的存储库,并且曾经有一些库,位于

common/shared/foo
子目录下。然后有些人决定切换到微服务,所以他们基本上制作了存储库的 X 个副本,并且在每个副本中删除了所有不相关的文件,将
foo
内容移动到根级别(所以以前在
common/shared/foo/src/ 下的内容) 
现在处于
src/
等之下;然后将其作为单个提交提交(后来称为“大爆炸”提交),然后在这些“迷你”存储库中进行了大约一年的开发。

现在,我想重写(清理)此类存储库中的历史记录,因此我在谷歌上搜索了一下并决定使用

git-filter-repo

 来实现这一点。但是,我找不到以不同方式处理子历史记录的选项组合:对于“大爆炸”之前的提交,它应该只过滤(保留在适当位置)涉及 
common/shared/foo
 子目录的提交;并且对于这些提交,将此子目录下的所有文件保留到根目录;对于“大爆炸”提交之后的所有提交,它应该保留所有“原样”。

有没有办法通过

git filter-repo

实现这一目标?谢谢

git git-filter-repo
1个回答
1
投票
您可以使用

--refs

 选项列出要处理的分支(或任何参考)
:

git branch that/point/in/time <commit sha> git filter-repo --refs that/point/in/time ...


一旦重写了

that/point/in/time

,您就可以将最近的历史记录插入到重写的序列之上:

# Replace the commit that initially was that/point/in/time with the rewritten one: git replace <previous sha> that/point/in/time # Run git filter-repo --force to rewrite the history of all branches as # If they happened on top of the new commit: git filter-repo --force

注意:上面的命令将简单地写入一个新的提交链,每个提交的内容按原样保留。检查您的历史记录,看看是否需要在交汇处添加一些额外的编辑。

© www.soinside.com 2019 - 2024. All rights reserved.