hg copy 有什么作用? [英] What does hg copy do?

查看:23
本文介绍了hg copy 有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们最近对存储库中的一个目录进行了hg copy.我们以为做一些类似 cp -ahg add 的事情,并且可能以某种方式标记这个文件是从 repo 中的另一个文件复制的(所以 hgannotate 显示原始提交者).但现在看来 hgcopy 可以做更多或不同的事情.我真的找不到关于复制究竟是如何工作的.所以:

  • hg copy 到底做了什么,有什么特殊处理未来的原因?
  • 如果事实证明对我们的案例做了错误的事情(tm)",我该怎么办将文件取消标记为另一个文件的副本?

(这个问题是在 Mercurial 邮件列表上提出的,您可能也想关注原始线程.)>

解决方案

  • hg copy 到底做了什么,有什么特殊处理未来的原因?

它添加新文件并将它们标记为旧文件的副本.因为它们是副本,所以在原始文件中所做的更改将合并到副本中.时间从左向右流动:

(init) --- (edit a.txt) ---- (a.txt编辑复制到b.txt)/(hg 复制 a.txt b.txt)

<块引用>

  • 如果事实证明对我们的案例做了错误的事情(tm)",我该怎么办将文件取消标记为另一个文件的副本?

此机制仅在您合并时生效.如果 b.txt 不存在于共同祖先修订(上图中的 init),然后 Mercurial 将向后搜索以查看 b.txt 是否是从其他地方复制的.

让我们以缩写形式继续上图:

(i) -- (edit a) -- (a edit copy to b) -- (edit a) -- (merge)//(copy a b) --/------- (edit b) ------------------/

问题是如何完成最终合并.共同祖先点现在是 copy a b 节点,这里 ab 都存在.这意味着不会有任何副本搜索!所以对 a 的第二次编辑不会合并为b.

为了仔细检查,我试了一下:

$ hg init$echo a >一个$ hg 添加一个$ hg commit -m init$ hg 复制 a b$ hg commit -m "copy a b"

这是副本,b 现在只包含 a.

$ hg 更新 0更新了 0 个文件,合并了 0 个文件,删除了 1 个文件,未解决了 0 个文件$ echo aa >>一个$ hg commit -m "编辑一个"创造了一个新的头$ hg 合并将 a 和 b 合并到 b更新了 0 个文件,合并了 1 个文件,删除了 0 个文件,未解决了 0 个文件(分支合并,不要忘记提交)$ hg commit -m "a 编辑已复制到 b"

这是第一次合并,对 a 的编辑已复制到 b 中:

$ cat b一个aa

我们现在同时进行更改:

$ echo aaa >>一个$ hg commit -m "再次编辑"$ hg 更新 3更新 1 个文件,合并 0 个文件,删除 0 个文件,未解析 0 个文件$回声 bbb >>乙$ hg commit -m "edit b"创造了新的头$ hg 合并更新 1 个文件,合并 0 个文件,删除 0 个文件,未解析 0 个文件(分支合并,不要忘记提交)

没有进一步复制:

$ cat a一个aa啊啊啊$猫乙一个aabbb

至于禁用此...您无法真正明确禁用副本检测.但正如我希望在上面说明的那样,它不会打扰"你第一次合并后再次.

如果第一次合并有问题,那么可以使用hg resolve --toolinternal:local 将文件重置为您之前的状态开始合并.所以与

$ hg resolve --tool internal:local b

我们可以将 b 带回仅包含一行和 a.

We recently did a hg copy of a directory in our repository. We thought it does something like cp -a and hg add and maybe flag somehow that this file has been copied from another file inside the repo (so hg annotate shows the original committer). But it now seems that hg copy does more or different stuff than that. I couldn't really find much on how exactly copy works. So:

  • What exactly does hg copy do and what special treatment does this cause in the future?
  • If it turns out to do "the wrong thing(tm)" for our case, how do I unflag the file as beeing a copy of another file?

(This question was asked on the Mercurial mailinglist, you may want to follow the original thread too.)

解决方案

  • What exactly does hg copy do and what special treatment does this cause in the future?

It adds new files and marks them as copies of the old files. Because they are copies, a change made in the original file will be merged into copy. Time flows from left to right:

(init) --- (edit a.txt) ---- (a.txt edit is copied to b.txt)
                           /
       (hg copy a.txt b.txt)

  • If it turns out to do 'the wrong thing(tm)' for our case, how do I unflag the file as beeing a copy of another file?

This mechanism only kicks in when you merge. If b.txt is not present in the common ancestor revision (init in the above graph), then Mercurial will do a search backwards to see if b.txt is copied from somewhere else.

Let us continue the above graph in abbreviated form:

(i) -- (edit a) -- (a edit copied to b) -- (edit a) -- (merge)
                 /                                   /
    (copy a b) --/------- (edit b) ------------------/

The question is how the final merge is done. The common ancestor point is now the copy a b node and here both a and b are present. This means that there wont be any search for copies! So the second edit to a wont be merged into b.

To double-check, I tried it out:

$ hg init
$ echo a > a
$ hg add a
$ hg commit -m init
$ hg copy a b
$ hg commit -m "copy a b"

This was the copy, b now contains a only.

$ hg update 0
0 files updated, 0 files merged, 1 files removed, 0 files unresolved
$ echo aa >> a
$ hg commit -m "edit a"
created a new head
$ hg merge
merging a and b to b
0 files updated, 1 files merged, 0 files removed, 0 files unresolved
(branch merge, don't forget to commit)
$ hg commit -m "a edit copied to b"

This was the first merge and the edit to a has been copied into b:

$ cat b
a
aa

We now make changes in parallel:

$ echo aaa >> a
$ hg commit -m "edit a again"
$ hg update 3
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ echo bbb >> b
$ hg commit -m "edit b"
created new head
$ hg merge
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
(branch merge, don't forget to commit)

There are no further copying done:

$ cat a
a
aa
aaa
$ cat b
a
aa
bbb

As for disabling this... you can't really explicitly disable the copy detection. But as I hope to have illustrated above, it wont "bother" you again after the first merge.

If the first merge is a problem, then you can use hg resolve --tool internal:local to reset the files back to their state before you started the merge. So with

$ hg resolve --tool internal:local b

we could have brought b back to just containing one line with a.

这篇关于hg copy 有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆