从Bitbucket历史记录中完全删除提交 [英] Completely remove commit from Bitbucket history

查看:572
本文介绍了从Bitbucket历史记录中完全删除提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我进行了错误的提交,并将其推送到我的私人bitbucket.org存储库中.如何从远程存储库的历史记录中完全删除此提交?

I've made a wrong commit and I pushed it to my private bitbucket.org repository. How can I completely remove this commit from the remote repository's history?

我尝试了以下操作:

git reset --hard HEAD~1
git reset HEAD~
git commit -m "some message"
git push -f

我是根据 Bitbucket git reset

但是,以前的提交可以通过Bitbucket的Web界面访问.

Yet, previous commits are accessible via Bitbucket's web interface.

我的意思是说,仍然可以通过https://bitbucket.org/user/repo/commits/<deleted commit hash>之类的链接来访问它们(尽管它们未在Web界面的存储库提交中列出).

I mean they are still accessible using a link like https://bitbucket.org/user/repo/commits/<deleted commit hash> (although they are not listed in repository commits in the web interface).

此信息(我打算删除的历史记录)是从我的存储库中获取的吗?

Is this information (the history which I intended to delete) fetched from my repository?

  1. bitbucket.org的某些功能吗?
  2. 我是否采取了某些错误措施?哪个?
  3. 如何从bitbucket.org上的历史记录中完全删除提交?

推荐答案

  1. 这是BitBucket和Git本身的组合功能. Git提交是不可变的对象.您不能在历史记录图中移动它们的位置,只能在其他位置创建新的提交,有时甚至删除大量的提交.

  1. This is a combined feature of both BitBucket and Git itself. Git commits are immutable objects. You can not move their position in the history graph, only create new commits in other locations, and sometimes delete swaths of commits.

分支只是一个移动标签(标签是与提交相关联的静态标签).当分支为HEAD时,您进行的所有提交都将标签与它们一起移动.您可以将同一标签移动到图形的无关部分,而不必前后移动.当您变基时,这就是发生的情况.在新的基础上创建的内容(大多与原始内容相同)的新提交,将移动分支标签以指向它们.您始终可以清除不属于本地存储库中分支的未引用提交.

A branch is just a moving label (a tag is a static label, tied to a commit). When a branch is HEAD, any commits you make move the label along with them. You can move the same label to an unrelated part of the graph, not necessarily just forward and back. When you rebase, that's exactly what happens. New commits with (mostly) the same content as the originals are created at the new base, and the branch label is moved to point to them. You can always purge unreferenced commits that don't belong to a branch on your local repo.

在本地工作时一切都很好.一旦开始使用遥控器,就必须考虑到您可能不是唯一使用回购协议的人.一旦完成了对重新分支的分支的强制推送,就会发生以下几件事:

This is all fine when you are working locally. Once you start working with remotes, you have to start taking into account that you may not be the only one using the repo. Once you've done a force push of a rebased branch, a couple of things happen:

  1. 新创建的提交被推送到远程
  2. 您要跟踪的分支的远程分支上的分支标签已更新为新提交

您或服务器不再引用旧分支中的提交,但它们仍然存在.实际上,克隆您的存储库的其他任何用户仍将指向其本地版本中的这些提交,直到他们明确更改其历史记录为止.实际上,如果他们要用力推动,则分支标签将立即移回原来的位置,从而丢弃您的基准.

The commits in the old branch are no longer referenced by you or the server, but they still exist. In fact, any other users that cloned your repo will still point to these commits in their local versions until they explicitly change the history on their end. In fact, if they were to do a force push, the branch label would move right back to where it was, discarding your rebase.

Git不会在克隆的存储库上施加层次结构.每个代码和其他代码一样,都代表了代码的真实状态.因此,显然未使用的提交会保留一段时间,即使它们没有出现在历史记录中的本地分支中也是如此.话虽如此,如果git达到一定的年龄而又没有新的后代,则git可以定期修剪这些未引用的提交.

Git does not impose a hierarchy on the repos you clone. Each one is as much a representation of the true state of your code as any other. For this reason, apparently unused commits are kept around for a while, even when they don't appear in the history a local branch. That being said, git can prune such unreferenced commits periodically if they reach a certain age without getting and new descendants.

鉴于上述信息,您没有做错任何事情.如果没有明确引用其哈希,将不会克隆已删除的提交.如果您将提交搁置足够长的时间,很有可能会被自动清除.如果那足够好,您可以顺其自然.另一方面,如果您再次需要放弃该提交,请继续阅读.

Given the information above, you didn't do anything wrong. The deleted commit is not going to be cloned without an explicit reference to its hash. There's a good chance that if you leave the commit alone long enough, it'll get purged automatically. If that's good enough, you can let it be. If, on the other hand, you reeeeaaaly need that commit gone, read on.

确保干净回购的最可靠方法是从头开始.您可以创建一个本地仓库,该仓库经过修剪,清除,并且通常符合您的规格.完成此操作后,您可以删除服务器副本.然后,使用原始名称创建一个新的空存储库,并将原始记录推送到该存储库.

The most reliable way to ensure a clean repo is to start from scratch. You can create a local repo that is pruned, purged, and generally to your spec. Once you've done that, you can delete the server copy. Then, create a new empty repo with the original's name, and push your pristine history to it.

这篇关于从Bitbucket历史记录中完全删除提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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