Git:如何在特定提交之前删除历史记录

标签 git git-filter-branch

即,我有:

root -- c1 -- c2 -- .. - c1000 -- c1001 -- c1002 -- .. -- c2000 -- top

我想拥有:

root = c1000 -- c1001 -- c1002 -- .. -- c2000 -- top

如何?

(我想我可以通过 git filter-branch 来做,但具体怎么做呢?)

(我当然知道这是改写历史的意思……)

最佳答案

我发现以下内容对于创建具有不同根目录的新存储库很有用(当您说在提交前删除历史记录时,我认为您会问这个问题):

git fast-export master~5..master | (cd ../newrepo.git && git init . && git fast-import && git checkout)

(您也可以在同一个仓库中执行上述操作)

关于Git:如何在特定提交之前删除历史记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7459209/

相关文章:

git - 从 git repo 中删除 '.git' 目录?

git - 我可以在之前的所有提交中更改我的名字和姓氏吗?

git - 如何重写 Git 历史,使所有文件都在一个子目录中?

带 Git 的 Spring Cloud 配置服务器 - 无法克隆或 checkout 存储库连接超时

php - Git使用私钥从带有shell_exec的PHP文件中获取

git - 在一次 git-filter-branch 中重命名多个姓名和电子邮件

git - 看不到 git filter-branch 提示的未暂存更改

php - 如何为 Laravel 项目设置 Git Repo 在克隆后运行?

git - .gitattributes 涂抹和清洁过滤器作为存储库的一部分

git - 继续实际提交吗?