删除/切断Git的修订/提交历史 [英] Remove / cut off Git's revision / commit history

查看:63
本文介绍了删除/切断Git的修订/提交历史的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,该项目包含对自己的另一个项目的跟踪,该项目已用作模板项目.现在,我想从存储库中完全删除这些跟踪.基本上,我想切断旧的垃圾提交.所以我有

I have a project that contains traces to another project of myself that I've used as a kind of a template project. Now I want to remove these traces entirely from the repository. Basically I want to cut off the old junk commits. So I have

A -- B -- C -- D -- E -- F

并希望得到类似的东西

D -- E -- F

其中 A-B-C 已从存储库中完全删除.

with A -- B -- C being completely removed from the repository.

推荐答案

假定 master 位于提交 F :

 # create a new branch with D's content
$ git checkout --orphan temp <d-sha1>
$ git commit

 # rebase everything else onto the temp branch
$ git rebase --onto temp <d-sha1> master

 # clean up
$ git checkout master
$ git branch -d temp


如果您要完全删除旧的松散对象( A B 和& C ),首先确保您确实拥有想要的东西.此操作无法撤消.确认您要的内容后,运行:


If you want to completely remove the old loose objects (A, B, & C), first make sure you have exactly what you want. This cannot be undone. Once you have confirmed it's what you want, run:

$ git reflog expire --expire=now --all
$ git gc --prune=now

这篇关于删除/切断Git的修订/提交历史的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆