hg:在一次更改中替换目录内容

时间:2014-09-02 18:02:17

标签: mercurial

使用hg,如何在一次更改中替换目录的内容?

更具体地说,我在我的仓库中检查了一个大型C ++库的标题,我想将它们(包括添加和删除文件)更新到最新版本的库中。我想在一次改变中做到这一点,而不是首先删除旧版本然后添加新版本,这将破坏测试并产生无用的差异。

2 个答案:

答案 0 :(得分:4)

在您的mercurial repo中:

# Change to parent directory of your vendor directory
cd vendor_dir/..
rm -rf vendor_dir
# unpack/copy/checkout new vendor sources into a new vendor_dir
# Tell mercurial to figure out what changed
# Feel free to play with the similarity percentage and the (-n) do nothing switch
hg addremove --similarity 70 vendor_dir
hg commit vendor_dir

更新:

  1. 由于hg rm *内的vendor_dir错过了点文件(如果有),因此更改为在父目录上工作。
  2. hg rm更改为rm -rf,因为我错误地认为rm之后的addremove会做正确的事情。提示:它没有。
  3. 意识到默认的100%相似度不适合供应商发布。

答案 1 :(得分:2)

如果它们全部改变了,那么(假设一个平面的目录结构:

hg remove \path\to\directory\to\replace\*.h
copy \path\to\new\files\*.* \path\to\directory\to\replace\
hg add \path\to\directory\to\replace\*.*
hg commit -m "Library SoAndSo headers replaced"
hg push

第一行说忘记下一次提交中的所有文件,但是然后在同一次提交中添加新文件 - 记住只有最后一行而是一行实际上更改了存储库的本地副本而它只是公开在最后一行

如果您有子目录,那么您只需删除第一行的*.h,使用xcopy或资源管理器将新目录结构复制到位并删除*.*在第3行。