在 Mercurial 中撤消删除操作

发布于 2024-08-19 16:11:11 字数 75 浏览 5 评论 0原文

假设我在工作目录中进行了一些更改,并且意外地将多个文件(包括一些修改过的文件)标记为要删除。如何取消文件的删除标记而不丢失我所做的更改?

Suppose that I have made some changes in the working directory and accidentally marked several files (that include some of the modified ones) for removal. How do I unmark the files for removal without losing the changes I have made?

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

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

发布评论

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

评论(8

梦言归人 2024-08-26 16:11:11

只需 hg add 文件即可。

我不知道为什么您会得到许多修改工作目录的答案。如果您不小心标记了某些文件以进行删除,您可以使用 add 来撤消它。

ry4an@four:~/hgtest$ hg status --all
M another_file
C a_file
ry4an@four:~/hgtest$ hg remove --after --force *
ry4an@four:~/hgtest$ hg status --all
R a_file
R another_file
ry4an@four:~/hgtest$ hg add *
ry4an@four:~/hgtest$ hg status --all
M another_file
C a_file

也就是说,不要将 --forcehg remove 一起使用,或者永远不要使用。还要尝试养成使用hgforget而不是hgremove--after的习惯,

Just hg add the files.

I don't know why you're getting some many answers that modify the working directory. If you've accidentally marked some files for removal you can undo it with add.

ry4an@four:~/hgtest$ hg status --all
M another_file
C a_file
ry4an@four:~/hgtest$ hg remove --after --force *
ry4an@four:~/hgtest$ hg status --all
R a_file
R another_file
ry4an@four:~/hgtest$ hg add *
ry4an@four:~/hgtest$ hg status --all
M another_file
C a_file

That said, don't use --force with hg remove or ever really. Also try to get in the habit of using hg forget instead of hg remove --after,

思念绕指尖 2024-08-26 16:11:11

使用 hg revert 有两个选项:

hg revert -a

会去回到之前的版本,并将所有更改放入新文件中,并将 .orig 附加到名称

hg revert [要取消删除的文件名] 中,以恢复那些

我可能会选择后者的文件

there are two options using hg revert :

hg revert -a

which will go back to the previous revision and put all your changes in new files with .orig appended to the names

hg revert [names of files to unremove] to just revert those files

i'd probably go with the latter

场罚期间 2024-08-26 16:11:11

hg revert

我非常确定 Mercurial 甚至会默认备份您的更改。

hg revert

I'm pretty sure Mercurial even makes backups of your changes by default.

隔纱相望 2024-08-26 16:11:11

如果该文件存在(可能是您已使用 hg忘记 将其标记为删除,或者您修改了它,然后hg删除),请执行hg add [file] 将其添加回来,并包含上次提交之后和忘记文件之前所做的任何更改。

如果该文件不存在(可能该文件未经修改,并且您已使用 hg remove 将该文件标记为要删除),请执行 hg revert [file] 将其恢复返回到其在工作目录的父目录中的状态。

If the file exists, (likely if you've marked it for removal with hg forget or if you've modified it then hg removed it), do hg add [file] to add it back with any changes made after the last commit and before forgetting the file.

If the file does not exist (likely if the file was unmodified and you've marked the file for removal using hg remove), do hg revert [file] to revert it back to its state in the parent of the working directory.

温柔一刀 2024-08-26 16:11:11

我遇到了完全相同的问题。 hg addhg忘记 相反(正如相反的情况一样)。但是,尝试重新添加目录本身不起作用。相反,我必须在每个文件上使用 hg add

hg st | egrep "^R" | sed -e "s/R //" | xargs hg add

希望有帮助。请注意,就我而言,我没有任何合法想要删除的内容。如果您确实想要删除文件,请相应地调整 grep。

I had the exact same problem. hg add is the inverse to hg forget (just as the opposite is true). However, attempting to re-add the directory itself did not work. Instead, I had to use hg add on each file:

hg st | egrep "^R" | sed -e "s/R //" | xargs hg add

Hope that helps. Note that in my case, there was nothing I legitimately wanted to remove. If you have files you definitely want to remove, adjust the grep accordingly.

紅太極 2024-08-26 16:11:11

根据您对 jk 的评论,我检查了 hg忘记。它似乎只是 hg remove -Af 的快捷方式,这意味着这与 hg add 真正相反。

接下来,如果您使用过 hg remove -Af,那么您应该能够使用 hg add 恢复它(我刚刚尝试过,似乎有效)。

Following your comment to jk, I checked hg forget. It seems to be just a shortcut for hg remove -Af, meaning that this is the real opposite of hg add.

Following that, if you've used hg remove -Af, then you should be able to revert that using hg add (I just tried it and seems to work).

宁愿没拥抱 2024-08-26 16:11:11

标记存储在 .hg/dirstate 文件中。在发出 hg remove -Af 之前,您需要做的就是获取一个。它可能看起来像这样(未经测试):

hg clone bad-repo orig-repo
cp orig-repo/.hg/dirstate bad-repo/.hg/dirstate
cd bad-repo
hg status

最后一个命令应显示删除文件之前的状态。

The markers are stored in .hg/dirstate file. All you need to do i to get a one from before issuing hg remove -Af. It may look like this (not tested):

hg clone bad-repo orig-repo
cp orig-repo/.hg/dirstate bad-repo/.hg/dirstate
cd bad-repo
hg status

The last command should show the status from before removing files.

夏末染殇 2024-08-26 16:11:11

我删除了一堆未修改的文件:

hg remove *

这是我必须做的才能将它们恢复:

hg revert --all

没有其他工作。不是 hg add 不是 hg add * 也不是 hg revert *

I removed a bunch of unmodified files:

hg remove *

This is what I had to do to get them back:

hg revert --all

Nothing else worked. Not hg add not hg add * nor hg revert *

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