在 Mercurial 中,将旧文件移动到位置,将新文件移动到具有相同名称的旧文件位置
In Mercurial, move old file to location, move new files into old file location with same names
这应该很简单,但有些地方不太对劲。这是我的场景,然后我将简要概述我正在使用的命令。知道我们有 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.
即使我忽略了上面的 "modified" 怪癖,当我将这个新分支与程序员所做的其他更改合并到暂存分支时,它会抱怨 "local has this which remote deleted"。我真的不关心其中的大部分内容,因为我可以直接发布它,然后任何新分支都会有这个变化。我关心的是,在 currentDir-beta 文件夹中对来自其他程序员的那些 "common" 文件所做的任何工作将不再映射到新位置。我可以 copy/paste 代码并提交它,但这基本上意味着这些分支被清理了,因为它与保留其他程序员对这些公共文件所做的更改有关。举例说明我的意思,当我合并并键入 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 中发生的现有代码更改在暂存环境中 "forwarded" 到 currentDir/ 。映射所有其他 "not common" 文件更改,只是不映射这些常见文件。
更新
忘了说,我在 macOS Sierra 上使用 Mercurial 3.9。
我不知道
- 你的 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
如您所见 - 根本没有编辑("Modified")(这里日志/per changeset/比aggregated status 更正确)
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
综合结果考虑只有边界条件是(正确地,从技术上讲)修改 files for files 1) 在相同的位置 2) 具有相同的名称 3) 并且具有更改的内容
这应该很简单,但有些地方不太对劲。这是我的场景,然后我将简要概述我正在使用的命令。知道我们有 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.
即使我忽略了上面的 "modified" 怪癖,当我将这个新分支与程序员所做的其他更改合并到暂存分支时,它会抱怨 "local has this which remote deleted"。我真的不关心其中的大部分内容,因为我可以直接发布它,然后任何新分支都会有这个变化。我关心的是,在 currentDir-beta 文件夹中对来自其他程序员的那些 "common" 文件所做的任何工作将不再映射到新位置。我可以 copy/paste 代码并提交它,但这基本上意味着这些分支被清理了,因为它与保留其他程序员对这些公共文件所做的更改有关。举例说明我的意思,当我合并并键入 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 中发生的现有代码更改在暂存环境中 "forwarded" 到 currentDir/ 。映射所有其他 "not common" 文件更改,只是不映射这些常见文件。
更新
忘了说,我在 macOS Sierra 上使用 Mercurial 3.9。
我不知道
- 你的 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
如您所见 - 根本没有编辑("Modified")(这里日志/per changeset/比aggregated status 更正确)
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
综合结果考虑只有边界条件是(正确地,从技术上讲)修改 files for files 1) 在相同的位置 2) 具有相同的名称 3) 并且具有更改的内容