简体   繁体   English

删除不在历史记录中的git commit

[英]Remove git commit that is not in history

I had something like this: 我有这样的事情:

A - B - C

I amended C and I had: 我修改了C,然后得到:

A - B - D

And C in floating somewhere else, how can I delete C from local and remote repository? C漂浮在其他地方,如何从本地和远程存储库中删除C?

There are no pointers to C. But I can read its hash in Github. 没有指向C的指针。但是我可以在Github中读取其哈希值。 How can I force the garbage collection and push this to remote? 如何强制垃圾收集并将其推送到远程?

From github support 来自github支持

Be warned that force-pushing does not erase commits on the remote repo, it simply introduces new ones and moves the branch pointer to point to them. 请注意,强制推送不会删除远程存储库上的提交,它只会引入新的提交,并将分支指针移动到指向它们的位置。 If you are worried about users accessing the bad commits directly via SHA1, you will have to delete the repo and recreate it. 如果您担心用户直接通过SHA1访问错误的提交,则必须删除该存储库并重新创建它。

Thanks. 谢谢。

You'll need to be a bit more specific about what you really did, what refs (heads, "pointers") point to which commits, etc. before you can get a specific answer. 在获得具体答案之前,您需要更加详细地说明您的实际工作,引用(标题,“指针”)指向哪些提交等。

In general, if no refs point to your old commit, C, then it will be garbage collected in time. 通常,如果没有引用指向您的旧提交C,那么它将被及时垃圾回收。

If you have refs pointing to C and you want C to disappear, you need to remove those refs. 如果您有指向C的引用,并且您希望C消失,则需要删除这些引用。 Of course, you need to understand the potential effects of doing that - ie what other commits might disappear. 当然,您需要了解这样做的潜在影响-即其他提交可能会消失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM