在 Mercurial 中撤消删除操作
假设我在工作目录中进行了一些更改,并且意外地将多个文件(包括一些修改过的文件)标记为要删除。如何取消文件的删除标记而不丢失我所做的更改?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
只需
hg add
文件即可。我不知道为什么您会得到许多修改工作目录的答案。如果您不小心标记了某些文件以进行删除,您可以使用 add 来撤消它。
也就是说,不要将
--force
与hg 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.
That said, don't use
--force
withhg remove
or ever really. Also try to get in the habit of usinghg forget
instead ofhg remove --after
,使用 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
hg revert
我非常确定 Mercurial 甚至会默认备份您的更改。
hg revert
I'm pretty sure Mercurial even makes backups of your changes by default.
如果该文件存在(可能是您已使用
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 thenhg remove
d it), dohg 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
), dohg revert [file]
to revert it back to its state in the parent of the working directory.我遇到了完全相同的问题。
hg add
与hg忘记
相反(正如相反的情况一样)。但是,尝试重新添加目录本身不起作用。相反,我必须在每个文件上使用hg add
:希望有帮助。请注意,就我而言,我没有任何合法想要删除的内容。如果您确实想要删除文件,请相应地调整 grep。
I had the exact same problem.
hg add
is the inverse tohg forget
(just as the opposite is true). However, attempting to re-add the directory itself did not work. Instead, I had to usehg add
on each file: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.
根据您对 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 forhg remove -Af
, meaning that this is the real opposite ofhg add
.Following that, if you've used
hg remove -Af
, then you should be able to revert that usinghg add
(I just tried it and seems to work).标记存储在 .hg/dirstate 文件中。在发出
hg remove -Af
之前,您需要做的就是获取一个。它可能看起来像这样(未经测试):最后一个命令应显示删除文件之前的状态。
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):The last command should show the status from before removing files.
我删除了一堆未修改的文件:
这是我必须做的才能将它们恢复:
没有其他工作。不是
hg add
不是hg add *
也不是hg revert *
I removed a bunch of unmodified files:
This is what I had to do to get them back:
Nothing else worked. Not
hg add
nothg add *
norhg revert *