Mercurial:如何合并对在另一个分支中重命名的文件的更改?

发布于 2024-09-29 10:08:02 字数 1551 浏览 1 评论 0原文

我有一个 Mercurial 存储库,其中有四个分支。一个是“公共”分支,其他三个是“特定”分支,其中包括应用于公共分支的一些外观更改。其中一项外观更改包括重命名一些文件。

因此,公共分支具有“file.txt”,第一个特定分支具有“file-01.txt”,这是相同的文件,用于相同的目的但名称不同并且略有不同内容。它在特定分支上被重命名为 file-01.txt,并且“hg log -f file-01.txt”正确显示了重命名之前的历史记录。

当我对公共分支上的 file.txt 进行更改时,我需要能够将该更改合并到特定分支上的 file-01.txt 中。但 Mercurial 不知道这些文件是相同的。它告诉我:

远程修改了本地删除的file.txt

使用 (c) 已挂起的版本还是保留 (d) 删除的版本?

如果我选择“c”,那么我会得到一个新的 file.txt,其中包含公共分支版本中的确切内容。如果我选择“d”,则根本不会合并更改。

我该怎么做才能解决这个问题?


编辑:我可以使其在新的测试存储库中正常工作,但不能在我的实际存储库中正常工作。这是我得到的结果(请注意,rev 118 位于特定分支上,就在原始重命名之前,因此我将再次执行重命名过程来进行说明):

C:\...> hg更新-C 118

0 个文件已更新、0 个文件已合并、0 个文件已删除、0 个文件未解决

C:\...> hg 合并默认

合并文件.txt
合并 anotherfile.txt
0 个文件已更新,2 个文件已合并,0 个文件已删除,0 个文件未解决
(分支合并,不要忘记提交)

所以它无需重命名即可工作。但如果我重命名,就会失败:

C:\...> hg更新-C 118

更新了 2 个文件,合并了 0 个文件,删除了 0 个文件,解决了 0 个文件

C:\...> hg 重命名 file.txt file-01.txt
C:\...> hg commit -m“重命名”

创建了新头

C:\...> hg 合并默认

远程更改了本地删除的file.txt
使用 (c) 已挂起的版本还是保留 (d) 已删除的版本?


编辑2:这是我在最后一步从 hg merge --debug default 得到的内容:

正在搜索版本 115 的副本
本地不匹配的文件:
文件-01.txt
找到的所有副本(* = 合并,! = 发散):
文件-01.txt ->文件.txt

检查目录重命名
解决清单
覆盖 None 部分 False
祖先 9d979018c2df 本地 f842fdbc252b+ 远程 05fc75e480da
anotherfile.txt:版本不同 ->米
远程更改了本地删除的file.txt
使用 (c) 已挂起的版本还是保留 (d) 已删除的版本?

I have a Mercurial repository with four branches in it. One is the "common" branch, the other three are "specific" branches which consist of some cosmetic changes applied to the common branch. One of those cosmetic changes consisted of renaming some files.

So the common branch has "file.txt", and the first specific branch has "file-01.txt" which is the same file, used for the same purpose but has a different name and slightly different contents. It was renamed to file-01.txt on the specific branch, and "hg log -f file-01.txt" correctly shows the history going back to before the rename.

When I make a change to file.txt on the common branch, I need to be able to merge that change into file-01.txt on the specific branch. But Mercurial doesn't understand that the files are the same. It tells me:

remote changed file.txt which local deleted

use (c)hanged version or leave (d)eleted?

If I pick "c" then I get a new file.txt containing exactly what's in the common branch's version. If I pick "d" then the change isn't merged at all.

What can I do to get this right?


EDIT: I can make it work correctly in a fresh test repository, but not my actual repo. Here's what I get (note that rev 118 is on the specific branch, just before the original rename, so I'm going through the rename process again to illustrate):

C:\...> hg update -C 118

0 files updated, 0 files merged, 0 files removed, 0 files unresolved

C:\...> hg merge default

merging file.txt
merging anotherfile.txt
0 files updated, 2 files merged, 0 files removed, 0 files unresolved
(branch merge, don't forget to commit)

So it works without the rename. But if I rename, it fails:

C:\...> hg update -C 118

2 files updated, 0 files merged, 0 files removed, 0 files resolved

C:\...> hg rename file.txt file-01.txt
C:\...> hg commit -m "renamed"

created new head

C:\...> hg merge default

remote changed file.txt which local deleted
use (c)hanged version or leave (d)eleted?


EDIT 2: Here's what I get at that last step from hg merge --debug default:

searching for copies back to rev 115
unmatched files in local:
file-01.txt
all copies found (* = to merge, ! = divergent):
file-01.txt -> file.txt

checking for directory renames
resolving manifests
overwrite None partial False
ancestor 9d979018c2df local f842fdbc252b+ remote 05fc75e480da
anotherfile.txt: versions differ -> m
remote changed file.txt which local deleted
use (c)hanged version or leave (d)eleted?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月亮邮递员 2024-10-06 10:08:02

我最终将问题追溯到历史中的一个特定修订:只要不涉及该修订,我就可以合并重命名。仍然不确定该修订版出了什么问题,但我重新进行了更改,现在它可以工作了。

I ended up tracking the problem down to one particular revision in the history: I could merge across the rename as long as that revision wasn't involved. Still not sure what went wrong with that revision, but I redid the changes and it's working now.

原谅我要高飞 2024-10-06 10:08:02

问题在于您如何处理分支中的重命名。从表面上看,您(或您的 GUI)对旧名称 file.txt 进行了“删除”,然后添加了名为 file-01.txt 的该文件的副本。

当你这样做时,mercurial 并不知道它们之间有联系。但是,如果您在分支中使用了以下命令:

hg rename file.txt file-01.txt

则 file.txt 中的更改将应用​​于 file-01.txt,而不是您看到的消息。然而,如果没有您的帮助,mercurial 就无法知道它们之间的联系。

The problem is with how you handled the rename in the branch. From the looks of it you (or your GUI) did a 'remove' on the old name, file.txt, and then did an add of a copy of that file named file-01.txt.

When you do it that way, mercurial has no idea they're linked. If, however, you had, in the branch, used the command:

hg rename file.txt file-01.txt

then rather than the message you're seeing the changes from file.txt would be applied to file-01.txt. However, without your help mercurial can't know they're linked.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文