在Mercurial中意外地提交了大量原始数据,如何防止它重载我的bitbucket存储库?

时间:2021-04-03 16:26:52

I copied a large amount of data from my labs file server to my laptop, then accidentally committed it to the Mercurial repository I'm using to back up my thesis.

我将实验室文件服务器上的大量数据复制到我的笔记本电脑上,然后不小心将其提交给了我正在使用的用于备份论文的水银储存库。

Now I have 200+ MB of data I don't need taking up space on my hard disk, even after I've deleted the files. This isn't really a problem, but the bitbucket repository I sync to only gives me 1 GB of space, which I will need for my data.

现在我有200多MB的数据,我不需要占用硬盘上的空间,即使我已经删除了文件。这并不是真正的问题,但是我同步的位桶存储库只给了我1gb的空间,这是我需要的数据。

Stupidly I then deleted the files and committed again, so I can't just use rollback as described in https://*.com/a/3290523/961959 without creating a new repository and having to reset up everything with bitbucket.

然后,我愚蠢地删除了这些文件并再次提交,所以我不能只使用在https://*.com/a/3290523/961959中描述的回滚,而不需要创建一个新的存储库,并且必须用bitbucket重置所有内容。

Is there a way I can fix this, so I don't waste a quarter of my repository space? Can I rollback the last 2 commits I did?

是否有一种方法可以修复这个问题,这样我就不会浪费1 / 4的存储库空间?我可以回滚我最后两次提交吗?

3 个解决方案

#1


4  

I'm going to describe what I would do if I wanted to roll back two most recent commits.

我将描述如果要回滚最近的两个提交,我将做什么。

I assume that you haven't pushed to Bitbucked yet. I also assume you have these changesets on top of your DAG:

我猜你还没想过要动手术。我还假设你在你的DAG上面有这些变更集:

o  C: Deleted files FILE1 and FILE2
|
o  B: Some nice changes; also added large files FILE1 and FILE2
|
o  A: Some good changeset

Here, C should be removed altogether, B should be edited (FILE1 and FILE2 additions should be rolled back), and A and below should be left as they are.

在这里,C应该被全部删除,B应该被编辑(FILE1和FILE2添加的内容应该回滚),A和下面应该保持原样。

Caveat: this only works if B and C were not pushed onto Bitbucked (or any other public repo) yet.

警告:只有当B和C还没有被推到位(或任何其他公开的回购)时,这才有效。

You'll need to enable the MQ extension to do this. To do this, add these lines to the .hg/hgrc file in your repo:

您需要启用MQ扩展来实现这一点。为此,在您的repo中将这些行添加到.hg/hgrc文件中:

[extensions]
mq=

Steps

First, I strip C:

首先,我带C:

$ hg strip C

Now, C is obliterated, and the parent is B. I import B as a Mercurial Queues patch to edit it:

现在,C被消去了,父结点是B,我将B作为一个多变队列补丁导入编辑:

$ hg qimport -r B -n B.patch

Now I have one patch on top our queue, which was created from B. I remove the big files, and refresh the patch:

现在我在我们的队列上有一个补丁,它是从b创建的,我删除了大文件,并刷新补丁:

$ hg forget FILE1 FILE2 
$ hg qrefresh

Now B.patch no longer includes the big files. However, they are still on the disk, albeit not controlled bu Mercurial. I now finish my work with MQ:

现在B。补丁不再包含大文件。但是,它们仍然在磁盘上,尽管不受控制。我现在用MQ完成我的工作:

$ hg qfinish -a

Here's what I have at the moment:

以下是我目前的想法:

o  B1: Some nice changes, no big files here
|
o  A: Some good changeset

#2


5  

You can:

您可以:

  1. Use hg strip to remove the changeset where you've added the files and all of its descendants (note that this will obliterate them completely, so only do it if these files are the only thing committed during this time).
  2. 使用hg带删除已添加文件及其所有子项的变更集(注意,这将完全删除它们,因此只有当这些文件是在此期间提交的惟一文件时才执行)。
  3. Import those changesets to MQ and edit them.
  4. 将这些变更集导入MQ并编辑它们。
  5. Use hg convert from Mercurial to Mercurial with --filemap option.
  6. 使用hg转换从水银到水银与-filemap选项。
  7. Clone your repository up to faulty changeset and push from this one instead, as described in FAQ.
  8. 将您的存储库复制到有问题的变更集,并按FAQ中所描述的那样从这个变更集进行推送。

#3


0  

In case the changes are already pushed to BitBucket, it does offer an option to strip changesets from the server. After performing the strip locally, you should access the url:

如果更改已经被推到BitBucket,那么它提供一个从服务器中删除变更集的选项。在本地执行该条带后,您应该访问该url:

https://bitbucket.org/<user>/<repo>/admin/strip

It'll offer an option to strip all changes following a specific commit.

它将提供一个选项,可以在特定的提交之后删除所有更改。

NOTE: There used to be a link to reach that URL in the repo config menu. Now the only way to access it seems to be typing it directly.

注意:在repo config菜单中曾经有一个链接来访问该URL。现在访问它的唯一方法似乎是直接输入。

#1


4  

I'm going to describe what I would do if I wanted to roll back two most recent commits.

我将描述如果要回滚最近的两个提交,我将做什么。

I assume that you haven't pushed to Bitbucked yet. I also assume you have these changesets on top of your DAG:

我猜你还没想过要动手术。我还假设你在你的DAG上面有这些变更集:

o  C: Deleted files FILE1 and FILE2
|
o  B: Some nice changes; also added large files FILE1 and FILE2
|
o  A: Some good changeset

Here, C should be removed altogether, B should be edited (FILE1 and FILE2 additions should be rolled back), and A and below should be left as they are.

在这里,C应该被全部删除,B应该被编辑(FILE1和FILE2添加的内容应该回滚),A和下面应该保持原样。

Caveat: this only works if B and C were not pushed onto Bitbucked (or any other public repo) yet.

警告:只有当B和C还没有被推到位(或任何其他公开的回购)时,这才有效。

You'll need to enable the MQ extension to do this. To do this, add these lines to the .hg/hgrc file in your repo:

您需要启用MQ扩展来实现这一点。为此,在您的repo中将这些行添加到.hg/hgrc文件中:

[extensions]
mq=

Steps

First, I strip C:

首先,我带C:

$ hg strip C

Now, C is obliterated, and the parent is B. I import B as a Mercurial Queues patch to edit it:

现在,C被消去了,父结点是B,我将B作为一个多变队列补丁导入编辑:

$ hg qimport -r B -n B.patch

Now I have one patch on top our queue, which was created from B. I remove the big files, and refresh the patch:

现在我在我们的队列上有一个补丁,它是从b创建的,我删除了大文件,并刷新补丁:

$ hg forget FILE1 FILE2 
$ hg qrefresh

Now B.patch no longer includes the big files. However, they are still on the disk, albeit not controlled bu Mercurial. I now finish my work with MQ:

现在B。补丁不再包含大文件。但是,它们仍然在磁盘上,尽管不受控制。我现在用MQ完成我的工作:

$ hg qfinish -a

Here's what I have at the moment:

以下是我目前的想法:

o  B1: Some nice changes, no big files here
|
o  A: Some good changeset

#2


5  

You can:

您可以:

  1. Use hg strip to remove the changeset where you've added the files and all of its descendants (note that this will obliterate them completely, so only do it if these files are the only thing committed during this time).
  2. 使用hg带删除已添加文件及其所有子项的变更集(注意,这将完全删除它们,因此只有当这些文件是在此期间提交的惟一文件时才执行)。
  3. Import those changesets to MQ and edit them.
  4. 将这些变更集导入MQ并编辑它们。
  5. Use hg convert from Mercurial to Mercurial with --filemap option.
  6. 使用hg转换从水银到水银与-filemap选项。
  7. Clone your repository up to faulty changeset and push from this one instead, as described in FAQ.
  8. 将您的存储库复制到有问题的变更集,并按FAQ中所描述的那样从这个变更集进行推送。

#3


0  

In case the changes are already pushed to BitBucket, it does offer an option to strip changesets from the server. After performing the strip locally, you should access the url:

如果更改已经被推到BitBucket,那么它提供一个从服务器中删除变更集的选项。在本地执行该条带后,您应该访问该url:

https://bitbucket.org/<user>/<repo>/admin/strip

It'll offer an option to strip all changes following a specific commit.

它将提供一个选项,可以在特定的提交之后删除所有更改。

NOTE: There used to be a link to reach that URL in the repo config menu. Now the only way to access it seems to be typing it directly.

注意:在repo config菜单中曾经有一个链接来访问该URL。现在访问它的唯一方法似乎是直接输入。