在知道提交ID的情况下删除特定的提交 [英] Delete a specific commit knowing commit id

查看:78
本文介绍了在知道提交ID的情况下删除特定的提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我说我有一个包含以下提交的仓库(git版本1.7.1)

Lets say i have a repo (git version 1.7.1) that contains following commits

A-> B-> C-> D-> E ,而我的HEAD位于 E 上。现在我想删除C,同时保持 A->等所有内容不变B-> D-> E

A -> B -> C -> D ->E and my HEAD is on E. Now i want to delete C while keeping everything same like A -> B -> D -> E .

您能帮我怎么做吗?

推荐答案

您可以使用 git rebase -i B 进行此操作。但是请注意, D E 将被重写(获得不同的提交SHA),因此结果将为 A-> B-> D’-> E’ E'的内容应等于 E (减去在 C ,您现在将其丢弃),但ID会有所不同。这就是为什么您到处都会发现有关重新部署已提交的警告的原因,这些提交可能已被其他人用作新工作的基础。您正在重写历史记录,这将导致其他存储库中的混乱,除非他们期望如此。但是,如果这是一个私有存储库,或者您尚未推送,则应该重新排列提交。

You can do this with git rebase -i B. Note however, that D and E will be rewritten (get different commit SHAs), so the result will be A -> B -> D' -> E'. The content of E' should be equivalent to E (minus the changes that had been made in C which you are now discarding), but the ID will differ. This is why you find warnings everywhere about rebasing commits that have already been pushed and potentially may be used by others as the basis for new work. You're rewriting history, which will cause confusion in other repositories unless they are expecting it. However, if this is a private repository, or you haven't pushed yet, you should be fine rearranging commits.

这篇关于在知道提交ID的情况下删除特定的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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