Hg:无法在先前的提交中找到已删除的文件

时间:2014-05-05 15:01:11

标签: git mercurial

我有一个包含myrepo的目录f1.txt的仓库。

首先我将这些文件添加到repo

$ hg add
$ hg commit

Then I removed `f1.txt` and created `f2.txt` and made commit again

$ rm f1.txt
$ vim f2.txt # create file here

$ hg add 
$ hg commit

现在,当我结帐上一次提交时,我看不到f1.txt。为什么会这样? 我想可以在git中这样做!

1 个答案:

答案 0 :(得分:2)

更新(checkout)到上一次提交时,实际上忘了提交删除f2.txt文件。因此,您仍然有未提交的更改,并且更新回上一个更改集不会还原f1.txt文件。

这是你可能在status

上得到的
$ hg status
! f1.txt

您会看到f1.txt仍然缺失。

现在,要解决此问题,您实际上还需要提交删除文件。要做到这一点,最好使用addremove,或者保留您提到的相同样本:

$ hg addremove
$ hg commit

'Then I removed `f1.txt` and created `f2.txt` and made commit again

$ rm f1.txt
$ vim f2.txt # create file here

$ hg addremove
$ hg commit

您的回购将按照您的预期进行。

更新到上一个变更集时,获得正确状态的另一种方法是更新和清理:

hg update -C

这将删除未提交的更改,并且f1.txt将返回。

相关问题