有人在我们的中央存储库中提交了。我们如何恢复它?

发布于 2024-10-13 22:44:46 字数 176 浏览 4 评论 0原文

我们正在使用本地中央存储库,每个人都可以从其中推送和拉取。直到最近,该存储库仅包含 .hg 文件夹。然后有人直接在中央存储库中提交,创建一个没有父项(父项 = -1)也没有子项的“岛”变更集。正确的方法是将其添加到本地存储库中并推送更改。

有没有办法让中央存储库的工作副本恢复到仅包含 .hg 且不与特定变更集关联的状态?

We're using a local central repository where everyone pushes to and pulls from. Until recently this repository only contained the .hg folder. Then someone went ahead and committed directly in the central repository creating an "island" changeset with no parent (parent = -1) nor child. The correct way would have been to add it in a local repository and push the changes.

Is there any way to get the working copy of the central repository to get back to the state where it only contain .hg and not be associated with a specific changeset?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

桃气十足 2024-10-20 22:44:46

由于这是您的本地中央存储库,并且这些是编辑历史记录的命令,因此请采取一切预防措施,例如首先在存储库的副本上进行尝试。

回滚存储库中的最后一个事务。

hg strip rev 从存储库中删除 rev 修订版及其所有后代。

  • 另请参阅:

https://www.mercurial-scm.org/wiki/EditingHistory

如果您立即(或很快)发现错误,则只需使用hg strip REV即可回滚最新(一个或多个)更改。 ...

编辑:这以其原始形式回答了问题。 OP 此后编辑了该问题。

Since this is your local central repository and these are commands that edit history, please take every precaution, like trying things out on a copy of the repository first.

Roll back the last transaction in a repository.

hg strip rev removes the rev revision and all its descendants from a repository.

  • Also see:

https://www.mercurial-scm.org/wiki/EditingHistory

If you catch your mistake immediately (or reasonably soon), you can just use hg strip REV to roll back the latest (one or more) changes. ...

Edit: This answers the question in its original form. The OP has since edited the question.

所有深爱都是秘密 2024-10-20 22:44:46

只需删除除 .hg 文件夹之外的所有内容即可。

Just delete everything except the .hg folder.

染柒℉ 2024-10-20 22:44:46

如果我正确理解发生了什么,有人更改为存储库目录并将单个文件作为“添加的文件”提交,而没有首先从活动目录中检查任何更改集。

您最终得到的结果类似于以下历史图表:

0:a43f   1:2843   2:bc81   3:2947
 o ------ o ------ o ------ o

4:228f
 o

其中变更集 4:228f 将“null id”作为其父变更集。

根据是否要保留变更集 4:228f,您可以遵循以下策略之一:

选项 1:克隆存储库而不包含有问题的更改

您可以创建存储库的新克隆,并将修订版 3:2947 指定为目标修订。这会将更改 3:2947 及其所有祖先更改集拉入新存储库。由于有问题的变更集未链接到变更集 3:2947 的祖先,因此它不会成为新克隆的一部分。

我建议首先保存旧存储库,然后将所有内容移动到新克隆,例如您保存在其 .hg/ 目录中的任何特定于存储库的设置文件。

如果您当前的存储库位于 /work/repo/foo 中,执行此操作的一种方法是:

$ cd /work/repo
$ mv foo foo.bak
$ hg clone -r 2947 foo.bak newfoo

现在复制任何 .hg/ 设置文件,例如您的原始 .hg/hgrc 文件:

$ cp foo.bak/.hg/hgrc newfoo/.hg/hgrc

最后将新的 foo 存储库移至适当位置:

$ mv newfoo foo

选项 2:克隆存储库并保留但rebase 更改

执行与以下操作相同的操作之前,但在将 newfoo 存储库移动到位之前,请使用“hg export”命令从旧存储库中提取有问题的更改的副本。然后检查 newfoo 树中最尖端变更集的工作副本,并将有问题的变更的文件变更导入为当前历史图表的正常变更集。

因此,在 mv newfoo foo 之前,通过键入以下内容保存有问题的更改的补丁:

$ cd /work/repo/foo.bak
$ hg export -r 228f --git > /tmp/patchfile.diff

然后您可以签出新存储库的最新版本,并在当前版本之上重新导入补丁历史记录:

$ cd /work/repo/newfoo
$ hg update --clean tip
$ hg import /tmp/patchfile.diff

如果有问题的变更集仅添加了一个新文件,那么这应该可以正常工作,并且您已准备好将新存储库移动到位!

不过,在进行最终重命名之前,删除新存储库的工作副本文件可能是个好主意:

$ cd /work/repo/newfoo
$ hg update --clean null

If I understand correctly what happened, someone changed into the repository directory and committed a single file as an 'added file' without first checking out any changeset from the active directory.

What you ended up with is something like the following history graph:

0:a43f   1:2843   2:bc81   3:2947
 o ------ o ------ o ------ o

4:228f
 o

where changeset 4:228f has the "null id" as its parent changeset.

Depending on whether you want to keep changeset 4:228f or not, you can follow one of the following strategies:

Option 1: Clone the repository without the offending change

You can create a new clone of the repository, specifying revision 3:2947 as the target revision. This will pull change 3:2947 and all its ancestor changesets into the new repository. Since the offending changeset is not linked into the ancestry of changeset 3:2947, it will not be part of the new clone.

I recommend saving the old repository first, and then moving everything over to a new clone, e.g. any repository-specific setup files you keep in its .hg/ directory.

If your current repository lives in /work/repo/foo, one way to do this would be:

$ cd /work/repo
$ mv foo foo.bak
$ hg clone -r 2947 foo.bak newfoo

Now copy over any .hg/ setup files, e.g. your original .hg/hgrc file:

$ cp foo.bak/.hg/hgrc newfoo/.hg/hgrc

Finally move the new foo repository in place:

$ mv newfoo foo

Option 2: Clone the repository and keep but rebase the change

Do the same as before, but before you move the newfoo repository in place, use the "hg export" command to extract a copy of the offending change from the old repository. Then check out a working copy of the tip-most changeset in the newfoo tree and import the file changes of the offending change as a normal changeset of your current history graph.

So, right before mv newfoo foo, save the patch of the offending change by typing:

$ cd /work/repo/foo.bak
$ hg export -r 228f --git > /tmp/patchfile.diff

then you can check-out the latest revision of the new repository, and re-import the patch on top of your current history:

$ cd /work/repo/newfoo
$ hg update --clean tip
$ hg import /tmp/patchfile.diff

If the offending changeset merely adds a new file, this should work fine and you are ready to move the new repository in place!

Before doing the final rename though, it may be a good idea to remove the working-copy files of the new repository:

$ cd /work/repo/newfoo
$ hg update --clean null
小猫一只 2024-10-20 22:44:46

该命令:

hg update null

将存储库的工作目录更新到第一次提交之前的位置,因此工作目录中没有文件,并且 hgparents 显示 -1

如果您不需要,您仍然需要删除提交,但这是一个单独的问题/问题。

The command:

hg update null

Updates a repository's working directory to the point before the first commit, so there are no files in the working directory and hg parents shows -1.

You'll still need to remove the commit if you don't want it, but that's a separate question/issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文