简体   繁体   English

hg forget和hg remove有什么区别?

[英]What is the difference between hg forget and hg remove?

I want mercurial to remove several files from the current state of the repository. 我希望mercurial从存储库的当前状态中删除多个文件。 However, I want the files to exist in prior history. 但是,我希望文件存在于以前的历史记录中。

How do forget and remove differ, and can they do what I want? 如何forgetremove不同,他们可以做我想要的吗?

' hg forget ' is just shorthand for ' hg remove -Af '. ' hg forget '只是' hg remove -Af '的缩写。 From the ' hg remove ' help: 来自' hg remove '帮助:

...and -Af can be used to remove files from the next revision without deleting them from the working directory. ...和-Af可用于从下一版本中删除文件而不从工作目录中删除它们。

Bottom line: ' remove ' deletes the file from your working copy on disk (unless you uses -Af ) and ' forget ' doesn't. 底线:' remove '从磁盘上的工作副本中删除文件(除非您使用-Af ),' forget '不会。

The best way to put is that hg forget is identical to hg remove except that it leaves the files behind in your working copy. 把最好的办法是, hg forget相同hg remove 除了它叶子中的文件, 你的工作副本后面。 The files are left behind as untracked files and can now optionally be ignored with a pattern in .hgignore . 这些文件作为未跟踪文件留下,现在可以选择使用.hgignore的模式进行忽略。

In other words, I cannot tell if you used hg forget or hg remove when I pull from you. 换句话说,当我从你那里拉出来时,我无法判断你是否使用了hg forgethg remove A file that you ran hg forget on will be deleted when I update to that changeset — just as if you had used hg remove instead. 当我更新到该变更集时,您 hg forget运行的文件被删除 - 就像您使用了hg remove

From the documentation, you can apparently use either command to keep the file in the project history. 从文档中,您显然可以使用任一命令将文件保留在项目历史记录中。 Looks like you want remove, since it also deletes the file from the working directory. 看起来你想删除,因为它也从工作目录中删除文件。

From the Mercurial book at http://hgbook.red-bean.com/read/ : 来自http://hgbook.red-bean.com/read/上的Mercurial书:

Removing a file does not affect its history. 删除文件不会影响其历史记录。 It is important to understand that removing a file has only two effects. 重要的是要理解删除文件只有两个效果。 It removes the current version of the file from the working directory. 它从工作目录中删除当前版本的文件。 It stops Mercurial from tracking changes to the file, from the time of the next commit. 它阻止Mercurial从下次提交时开始跟踪对文件的更改。 Removing a file does not in any way alter the history of the file. 删除文件不会以任何方式改变文件的历史记录。

The man page hg(1) says this about forget: 手册页hg(1)说这是关于忘记:

Mark the specified files so they will no longer be tracked after the next commit. 标记指定的文件,以便在下次提交后不再跟踪它们。 This only removes files from the current branch, not from the entire project history, and it does not delete them from the working directory. 这仅从当前分支中删除文件,而不是从整个项目历史记录中删除文件,并且不会从工作目录中删除它们。

And this about remove: 这个关于删除:

Schedule the indicated files for removal from the repository. 安排指定的文件以从存储库中删除。 This only removes files from the current branch, not from the entire project history. 这仅从当前分支中删除文件,而不是从整个项目历史记录中删除。

If you use "hg remove b" against a file with "A" status, which means it has been added but not commited, Mercurial will respond: 如果对具有“A”状态的文件使用"hg remove b" ,这意味着它已被添加但未提交,Mercurial将响应:

  not removing b: file has been marked for add (use forget to undo)

This response is a very clear explication of the difference between remove and forget. 这种反应非常明确地说明了删除和遗忘之间的区别。

My understanding is that "hg forget" is for undoing an added but not committed file so that it is not tracked by version control; 我的理解是"hg forget"用于撤消添加但未提交的文件,以便版本控制不跟踪它; while "hg remove" is for taking out a committed file from version control. "hg remove"用于从版本控制中取出一个已提交的文件。

This thread has a example for using hg remove against files of 7 different types of status. 线程有一个示例,用于对7种不同类型状态的文件使用hg remove

A file can be tracked or not, you use hg add to track a file and hg remove or hg forget to un-track it. 可以跟踪或不跟踪文件,使用hg add跟踪文件和hg remove或hg忘记取消跟踪它。 Using hg remove without flags will both delete the file and un-track it, hg forget will simply un-track it without deleting it. 使用没有标志的hg删除将删除文件并取消跟踪它, hg忘记只是取消跟踪它而不删除它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM