从Mercurial中的提交中删除文件 [英] Remove file from a commit in Mercurial

查看:80
本文介绍了从Mercurial中的提交中删除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个提交,已经修改了一些文件.其中一些文件是我不希望在此提交中进行的修改的一部分. Mercurial中是否有一种方法可以从提交中删除某些文件,而又不会丢失对它们所做的更改?谢谢.

I have a commit onto which I have amended some files. Some of these files that were part of the amend I do not want in this commit. Is there a way in Mercurial to remove certain files from the commit without losing the changes I have made to them? Thank you.

步骤:

  1. 进行了一些更改
  2. hg commit -m
  3. 进行了一些其他更改(其中一些文件不小心被修改了)
  4. 汞修正

推荐答案

尝试一下:

hg forget somefile.txt
hg commit --amend

如果文件是新文件(即您使用过hg add).

If the file was new (i.e. you had used hg add).

如果该文件已经存在,请尝试:

If that file already existed try:

cp somefile.txt somefile.txt.bak
hg revert somefile.txt --rev .~1
hg commit --amend

这基本上是在告诉Mercurial将文件(somefile.txt)回到revert到它是一个修订版本之前的状态(--rev .~1).

Which is basically telling mercurial to revert the file (somefile.txt) back to the state it was one revision ago (--rev .~1).

只需确保在输入命令之前备份要还原的文件,以免丢失所做的更改.我的印象是mercurial会自动为您执行此操作,但是经过快速测试后,我不太确定.

Just make sure to back up the file you are reverting before entering the command so that you do not lose your changes. I was under the impression mercurial does this automatically for you, but after testing it quickly I'm not so sure.

这篇关于从Mercurial中的提交中删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆