本文介绍了Mercurial:合并在意外创建的子文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TLDR:我似乎在主项目的子文件夹中创建了一个单独的存储库.我怎样才能将它们结合起来?

TLDR: I seem to have created a separate repository in a subfolder of my main project. How can I combine them?

我有一个项目文件夹,我们称其为 BOB .我将(hg clone) BOB 克隆到一个名为 BOB2 的新文件夹中.为了添加新功能,我在 BOB2 上创建了一个名为 BOB-newfeatures 的子文件夹.我已经在这个 BOB-newfeatures 文件夹上工作了一段时间了,并且签到了很多东西.

I have a project folder, let's call it BOB. I cloned (hg clone) BOB to a new folder called BOB2. To add new features, I created a subfolder on BOB2 called BOB-newfeatures. I have been working on this BOB-newfeatures folder for a while, with many checkins.

今天,我意识到以某种方式为 BOB-newfeatures 创建了一个单独的存储库(直到今天,我对 BOB2 main都没有进行任何更改,所以我没有注意到未跟踪更改).如果我在 BOB2 上执行hg status,它将不知道子文件夹中的更改,反之亦然.

Today I realized that somehow I created a separate repository for BOB-newfeatures (I hadn't changed anything on BOB2 main until today so I hadn't noticed that changes weren't being tracked). If I do hg status on BOB2, it doesn't know about changes in the subfolder and vice versa.

有没有办法将它们缝合在一起?我知道我可以将 BOB-newfeatures 中的所有文件都hg add转换为 BOB ,但是后来我认为我丢失了所有签入历史记录.

Is there a way to stitch these together? I know I could hg add all of the files in BOB-newfeatures to BOB but then I think I lose all of my checkin history.

推荐答案

好的,我从(pp)开始用你的名字重建(希望)你的案子.

OK, I reconstructed (I hope) your case, with your names, starting from

BOB2>hg log -T "{node|short}\tFiles: {join(files, ', ')}\n"
25a16a8fea5e    Files: Sub/3.txt
bf3c6cacb4a4    Files: 1.txt, 2.txt
ff71a2b1bbe3    Files: 1.txt

和嵌套存储库

BOB2\BOB-newfeatures>hg log -T "{node|short}\tFiles: {join(files, ', ')}\n"
acac7d413ed2    Files: f1.txt
15a1f9cacf25    Files: f2.txt
f3055921fa01    Files: f1.txt

BOB2

BOB2>hg manifest
1.txt
2.txt
Sub/3.txt


解决问题的方法-使用--filemap 中转换扩展名相反,与Wiki相比,方向:这是将repo的子目录转换为单独的存储库的示例,我将存储库的根目录移至子文件夹


Method of solving problem - using Convert extension with --filemap in inversed, compared to Wiki, direction: it's example transform subdir of repo into separate repository, I'll move repository-root into subfolder

  • 地图文件,已准备好进行转换
rename . BOB-newfeatures

  • 转化
  • hg convert --filemap map z:\BOB2\BOB-newfeatures z:\BOB-newfeatures-conv
    initializing destination z:\BOB-newfeatures-conv repository
    scanning source...
    sorting...
    converting...
    2 New feature started
    1 Change 1
    0 Change 2
    

    • 测试结果
    • BOB-newfeatures-conv>hg log -T "{node|short}\tFiles: {join(files, ', ')}\n"
      a3b2c462a3b9    Files: BOB-newfeatures/f1.txt
      f5f1168cfe2f    Files: BOB-newfeatures/f2.txt
      da27a50a5cb6    Files: BOB-newfeatures/f1.txt
      

      将文件路径与嵌套仓库中的日志进行比较,请注意更改集的不同哈希值

      compare file-paths with log from nested repo, note different hashes for changesets

      • 下一个坏消息:您不能仅仅从BOB | BOB2提取到转换后的存储库中缺少的部分 easy
      BOB-newfeatures-conv>hg pull ../BOB2
      pulling from ../BOB2
      searching for changes
      abort: repository is unrelated
      

      即使使用--force(因为存储库是真正不相关的,并且不共享历史记录),您也会遇到脏"的合并存储库(root和BOB-newfeatures/中的更改是两行)拥有自己的根源和技巧的变化)

      Even with --force (because repositories are really unrelated and doesn't share history) you'll get "dirty" combined repository (changes in root and in BOB-newfeatures/ are two separate lines of changes with own roots and tips)

      BOB-newfeatures-conv>hg pull ../BOB2 -f
      pulling from ../BOB2
      searching for changes
      warning: repository is unrelated
      requesting all changes
      adding changesets
      adding manifests
      adding file changes
      added 3 changesets with 4 changes to 3 files (+1 heads)
      (run 'hg heads' to see heads, 'hg merge' to merge)
      

      最后一步,您必须将两个历史重新链接到一个共同点.就我而言,由于我的行为(将转换为具有BOB-newfeatures的历史记录的已转换存储库),我不得不在3-4-5之后链接0-1-2修订版(历史上较早的更改)而且我不知道有什么更优雅的方法,而不是使用这次--splicemap

      And at last step you have to re-link two histories into one common. In my case due to my actions (pulling to converted repository with pre-existing history of BOB-newfeatures) I had to link 0-1-2 revisions after 3-4-5 (historically earlier changes) and I don't know more elegant way to do it, than again convert (HG->HG) repository, with --splicemap this time

      带日志输出

      >hg log -T "{rev} {node}\n"
      5 25a16a8fea5e5b4dac42a0a6b2c8e82890c220a3
      4 bf3c6cacb4a4c22cb5720ddeab1ec5f8238a98c9
      3 ff71a2b1bbe30a56c9dabc9a7ddb2bbccad840af
      2 a3b2c462a3b917b3ba58daee3df2632875baee17
      1 f5f1168cfe2f4b6c67d0af8a9259665ae2d40bd5
      0 da27a50a5cb6246c03c6af7485ac7ffc33e62738
      

      可以创建规则"5后0"的拼接图(格式为"linerChildHash ParentHash")

      splicemap for rule "0 after 5" can be created (with format of oneliner "ChildHash ParentHash")

      da27a50a5cb6246c03c6af7485ac7ffc33e62738 25a16a8fea5e5b4dac42a0a6b2c8e82890c220a3
      

      最后一次转换

      >hg convert  --splicemap z:\map z:\BOB-newfeatures-conv z:\BOB3
      scanning source...
      sorting...
      converting...
      5 Initial data
      4 Changes
      3 More changes
      2 New feature started
      spliced in 25a16a8fea5e5b4dac42a0a6b2c8e82890c220a3 as parents of da27a50a5cb6246c03c6af7485ac7ffc33e62738
      1 Change 1
      0 Change 2
      

      预期效果良好

      这篇关于Mercurial:合并在意外创建的子文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 17:09