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

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

问题描述

我们最近在存储库中对目录进行了hg copy.我们以为 做类似cp -ahg add的操作,并且可能以某种方式进行标记 此文件已从存储库中的另一个文件复制而来(因此hg annotate显示原始提交者).但是现在看来hg copy的功能更多或不同.我真的找不到 关于复制工作原理的很多内容.所以:

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:

  • hg copy的作用到底是什么? 将来会造成什么?
  • 如果事实证明对于我们的情况而言是错误的事情(tm)",我该怎么办 取消将该文件标记为另一个文件的副本?
  • 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?

(此问题在Mercurial邮件列表中提出,您可能也想遵循原始主题.)

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

推荐答案

  • hg副本的功能是什么?这有什么特殊的处理方法 将来会造成什么?
  • 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)

  • 如果事实证明对我们的案例而言是错误的事情(tm)",我该怎么办 取消将该文件标记为另一个文件的副本?
  • 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?

此机制仅在您合并时启动.如果b.txt不存在于 共同祖先修订版(在上图中初始化),那么Mercurial将 向后搜索以查看是否从其他位置复制了b.txt.

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) ------------------/

问题是如何完成最终合并.共同祖先点 现在是copy a b节点,并且ab都存在.这表示 不会有任何搜索副本!因此,对a的第二次编辑不会 合并到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"

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

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"

这是第一次合并,对a的编辑已复制到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.

如果第一次合并有问题,则可以使用hg resolve --tool internal:local将文件重置为它们的状态,然后再进行操作. 开始合并.因此,

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

我们本可以将b带回到仅包含a的一行.

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

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

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