【问题标题】:In Mercurial, move old file to location, move new files into old file location with same names在 Mercurial 中,将旧文件移动到位置,将新文件移动到具有相同名称的旧文件位置
【发布时间】:2023-03-27 23:00:03
【问题描述】:

这应该很简单,但有些地方不太对劲。这是我的场景,然后我将简要概述我正在使用的命令。知道我们有 3 个特定的开发区,Live、Staging,当然还有我们自己的本地开发区会有所帮助。

我在我的网站上开发了一个新的“测试版”区域,该区域已经上线并进行了适当的测试。现在我准备将它从 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.

即使我忽略了上述“修改”的怪癖,当我将这个新分支与程序员所做的其他更改合并到暂存分支时,它也会抱怨“本地已远程删除了这个”。我真的不在乎其中的大部分内容,因为我可以直接把它扔掉,然后任何新的分支都会有这个变化。我关心的是,在 currentDir-beta 文件夹中对其他程序员的那些“通用”文件所做的任何工作都将不再映射到新位置。我可以复制/粘贴代码并提交它,但这基本上意味着这些分支已被冲洗掉,因为它与保留其他程序员对这些公共文件所做的更改有关。举个例子来说明我的意思,当我合并并输入 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。

【问题讨论】:

    标签: merge mercurial branch rename


    【解决方案1】:

    我不知道

    • 您的 Mercurial 版本
    • 操作系统

    但在我的带有 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
    

    如您所见 - 根本没有编辑(“已修改”)(这里记录 /per changeset/ 比 aggregated 状态更正确)

    PS:我无法即时看到您在 hg st 中的修订集的目的以及分支+合并的必要性

    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) 内容改变

    【讨论】:

    • 感谢您的精彩解释。因此,尽管关于您的 PS 和 PPS 的问题,当我合并两个分支时,暂存时 Current-beta/index.php 文件中存在的更改不会在我的本地存储库中正确合并到 Current/index.php .当前在该索引文件暂存中存在的所有更改,永远不要将其转移到“重命名”索引文件。这就是我所关心的。听起来,我应该接受它并处理它,它应该可以工作。
    • 这让我想知道,什么时候应该运行hg mv -A Current-beta/index.php Current/index.php
    • @ImmortalFirefly - 抱歉,在第二次 hg mv 之后无法理解 Current-beta/index.php IS Current/index.php 的想法。 为什么您要执行一些额外的操作?! mv -A 至少没用 - 移动已经发生并存储(正确)!!!!
    • @ImmortalFirefly - 也许hg log -f Current/index.php 会给你一些启示?
    • 当我在合并之前运行hg log -f Current/index.php 时,它会显示所有更改,并且看起来像我希望的那样。我感到困惑的是我运行命令将它与暂存分支合并,它有所有这些合并问题,然后我运行hg log -f Current/index.php(甚至在我提交合并之前),现在hg log 缺少所有预期的提交几秒钟前我在同一个文件上看到的。这是您在上面与您的 PSS 谈论的部分吗?在我提交合并后,这些提交会神奇地出现吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-14
    • 2020-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-12
    • 1970-01-01
    相关资源
    最近更新 更多