在Mercurial中,将旧文件移动到位置,将新文件移动到具有相同名称的旧文件位置

时间:2016-11-02 18:38:48

标签: merge mercurial branch rename

这应该很简单,但有些事情并不恰当。这是我的场景,然后我将简要介绍我使用的命令。有助于了解我们有3个特定的开发区域,Live,Staging,当然还有我们自己的本地开发区域。

我开发了一个新的" beta"我的网站已经上线并进行了适当的测试。现在我准备将它从beta目录移动到它应该的位置并移出旧的目录。当我在本地进行时,看起来很好,但是当我尝试将我的本地分支合并到临时分支时,它似乎没有正确映射文件,并且给了我一堆use (c)hanged version, (d)elete, or leave (u)nresolved?个提示。当我的旧目录具有与beta目录相同的文件时(例如index.php),问题就出现了。这是我的意思的一个简单例子:

currentDir/index.php
currentDir/update.php
currentDir/another_file.php

currentDir-beta/index.php
currentDir-beta/update.php
currentDir-beta/a_new_file.php
currentDir-beta/another_new_file.php

这是我的过程。

# creates a new branch from the live branch
hg branch new-branch-name

# move the current directory somewhere else
hg mv currentDir/* currentDir-old/

# commit...
hg com -m "moved current to -old"

# everything is fine up to this point

# move the beta directory to where the old one was
hg mv currentDir-beta/* currentDir/

# when I run hg st, it only shows that files are being removed from the -beta directory and added to the new/old directory

# commit
hg com -m "moved -beta to currentDir"

# when this commits is when the problems start happening. 
# At this point when I run this next command, it shows that
# currentDir/index.php and other common files are now "modified" instead of "added"
hg st --rev "max(ancestors('new-branch-name') and branch(live)):'new-branch-name'"

# then try to merge to staging
hg up staging
hg merge new-branch-name

# errors happen with "common" file names like index.php. It treats them as though they were only modified instead of added.

即使我忽略了上述"修改了" quirk,当我将这个新分支合并到临时分支中时,程序员已经完成了其他更改,它抱怨" local有远程删除"。我真的不会关心大部分内容,因为我可以直接抛出这个,然后任何新的分支都会有这种变化。我关心的是在currentDir-beta文件夹中完成的任何工作#34; common"来自其他程序员的文件将不再映射到新位置。我可以复制/粘贴代码并提交它,但它基本上意味着这些分支被清除,因为它与保持其他程序员对这些常见文件所做的更改有关。为了举例说明我的意思,当我合并并输入hg st时,它可能看起来像这样。

M currentDir/index.php
M currentDir/update.php
M currentDir/a_new_file.php # why is this M? It should be A right?
M currentDir/another_new_file.php # why is this M? It should be A right?
M currentDir-old/another_file.php # why is this M? It should be A right?
R currentDir/another_file.php
R currentDir-beta/index.php
R currentDir-beta/update.php
R currentDir-beta/a_new_file.php
R currentDir-beta/another_new_file.php

有关如何解决此问题的任何建议?我的目标是使其能够在currentDir-beta中发生的现有代码更改被转发"到临时环境中的currentDir /。所有其他"不常见"映射文件更改,而不是这些常见文件。

更新

忘记提及,我在MacOS Sierra上使用Mercurial 3.9。

1 个答案:

答案 0 :(得分:2)

我不知道

  • 您的Mercurial版本
  • OS

但在我的带有Mercurial-3.9.1的Win-box上,我的印象(和结果)不同

清除初始状态(由于懒惰而缩短文件夹)

>hg st -A
C Current-beta\a_new_file.php
C Current-beta\another_new_file.php
C Current-beta\index.php
C Current-beta\update.php
C Current\another_file.php
C Current\index.php
C Current\update.php

首先重命名

>hg mv Current Current-Backup
moving Current\another_file.php to Current-Backup\another_file.php
moving Current\index.php to Current-Backup\index.php
moving Current\update.php to Current-Backup\update.php

...提交详细信息已跳过...

第二次重命名

>hg mv Current-beta Current
moving Current-beta\a_new_file.php to Current\a_new_file.php
moving Current-beta\another_new_file.php to Current\another_new_file.php
moving Current-beta\index.php to Current\index.php
moving Current-beta\update.php to Current\update.php

和之后的工作目录(如预期的那样)

>hg st
A Current\a_new_file.php
A Current\another_new_file.php
A Current\index.php
A Current\update.php
R Current-beta\a_new_file.php
R Current-beta\another_new_file.php
R Current-beta\index.php
R Current-beta\update.php

...提交详细信息已跳过...

如果你想看看Mercurial是如何录制的:我乍看之下用了一些令人费解的东西来更好地解释输出

hg log -T "{rev}:{node|short}\n{if(file_adds,'\tAdded: {join(file_adds,', ')}\n')}{if(file_copies,'\tCopied: {join(file_copies,', ')}\n')}{if(file_dels,'\tDeleted: {join(file_dels,', ')}\n')}{if(file_mods,'\tModified: {join(file_mods,', ')}\n')}\n"

这是结果

2:98955fcb7e71
        Added: Current/a_new_file.php, Current/another_new_file.php, Current/index.php, Current/update.php
        Copied: Current/a_new_file.php (Current-beta/a_new_file.php), Current/another_new_file.php (Current-beta/another_new_file.php), Current/index.php (Current-beta/index.php), Current/update.php (Current-beta/update.php)
        Deleted: Current-beta/a_new_file.php, Current-beta/another_new_file.php, Current-beta/index.php, Current-beta/update.php

1:61068c6ba8a7
        Added: Current-Backup/another_file.php, Current-Backup/index.php, Current-Backup/update.php
        Copied: Current-Backup/another_file.php (Current/another_file.php), Current-Backup/index.php (Current/index.php), Current-Backup/update.php (Current/update.php)
        Deleted: Current/another_file.php, Current/index.php, Current/update.php


0:454486bc43e5
        Added: Current-beta/a_new_file.php, Current-beta/another_new_file.php, Current-beta/index.php, Current-beta/update.php, Current/another_file.php, Current/index.php, Current/update.php

如你所见 - 根本没有编辑(“修改”)(这里log / per changeset /比聚合状态更正确)

PS:我无法在hg st中看到你的revset的实时目的以及分支+合并的必要性

PPS:好的,我看到了

>hg st --rev "0:"
M Current\index.php
M Current\update.php
A Current-Backup\another_file.php
A Current-Backup\index.php
A Current-Backup\update.php
A Current\a_new_file.php
A Current\another_new_file.php
R Current-beta\a_new_file.php
R Current-beta\another_new_file.php
R Current-beta\index.php
R Current-beta\update.php
R Current\another_file.php

汇总结果在考虑仅边界条件时(正确地,技术上讲)已修改文件的文件1)在同一位置2 )具有相同的名称3)和更改的内容