我想从我的GitHub存储库中删除大约两年前的7/8提交。只有2/3的提交涉及任何代码,其余的只是添加和删除配置文件。
一些以前的开发人员上传并删除了超过650个重复的配置文件,这弄乱了我们的github统计页面。Stat Graph
我们试着用git rebase -i删除它们,但花了6个小时,大部分代码都消失了。
我们如何在不破坏其他提交历史的情况下删除这些古老的提交?我们目前正在对存储库中的所有代码进行重新编码,所以如果不保留这些单独提交的更改,这并不是什么大问题,但我们希望保留与旧代码一起进行的所有统计数据。
发布于 2017-12-11 22:30:56
强制性危险:重写项目历史是非常危险的!在尝试此操作之前,请确保您有备份,并极其谨慎地进行操作!
要删除项目中的一个特定提交(例如,几年前的提交),您可以:
git rebase -p --onto SHA^ SHA
其中SHA
是要删除的提交。
这些选项的文档如下:
-p, --preserve-merges
Recreate merge commits instead of flattening the history by replaying
commits a merge commit introduces. Merge conflict resolutions or
manual amendments to merge commits are not preserved.
--onto <newbase>
Starting point at which to create the new commits. If the --onto
option is not specified, the starting point is <upstream>. May
be any valid commit, and not just an existing branch name.
进行此更改后,您需要:
git push --force origin master
# ^^^^^^^
# !!!
发布于 2017-12-11 22:19:58
需要两个步骤:
丢弃所有杂乱的提交:
,
git rebase --交互式良好提交
-f筛选器-分支--树-筛选器'rm git配置文件‘头
git推送--强制源主机
请注意,强烈不鼓励强制推送,因为它会使您的repo的所有当前克隆不一致的。任何冲突都必须手动修复。
https://stackoverflow.com/questions/47761910
复制相似问题