Move folder/files between repositories without losing Change history

Asked

Viewed 1,301 times

5

Context:
I have a versioning environment in Mercurial using Tortoisehg for viewing and commits and files. I want to move a folder from one repository to another and without losing change history, would like to know if it is possible and how.

For the sake of explanation, let’s assume I have the repositories A and B, both being used for years, and with hundreds of changes.

Goal:
In the repository To I have the folder (and with about 200 files and various formats):

C:\Repositorios\A\projetos\projeto1\artefatos

So I would like to move the briefcase artifacts with its contents, to the repository B, of which has a different folder structure:

C:\Repositorios\B\objetos\arquitetura\etc\etc\artefatos

Thank you.

3 answers

2


Two repositories, the Old man and the New. Are totally different.

We need to add the contents of the old repository to the new repository. But each has its own branch default. What can we do to help Mercurial?

The solution seems simple: Create a new branch, in the old repository (one that does not exist in the new repository), Sincronize with the new repository, and merge (merge) this branch with the branch default. Check below for the following steps:

  1. Initial status of repositories Old man and the New. Estrutura do repositório velho In the Old One we have only the directory x1 inserir a descrição da imagem aqui In the New we have the structure a\b\c
  2. Change files in the Old repository by following the same structure as the New repository. Delete files that are not desired. Detect the changes correctly. pop-up de mudanças seleção de mudanças
  3. Create new branch in the Old repository, here called velhodefault. criação de ramo confirmação de ramo After creating the new branch, do commit (with all changes made in step 2).
  4. In the Old repository, add connection to the New repository. It can be a local path, using protocol file://. adicionar nova conexão
  5. To synchronize, choose the repository (the box on the side of the send button), and press the send button (icon with two yellow cylinders, and a green arrow directed up). enviar conteúdo de repositório velho para o novo At this time Mercurial will not accept to send the content. As mentioned above, they are two distinct repositories. We’ll have to force synchronization. erro na sincronização To force, you must press the button opções, situated in the section Sincronizar. Choose the option Força push ou pull and push the button Gravar. adicionar --force Note that the box will appear Opções Selecionadas: --force observar --force Try syncing again. Check how the content looks in the repository New. ramo velho no repositório novo
  6. All that remains now is to merge the contents of the Old repository, choosing the right branch. escolher o ramo para mesclar Push the button Avançar. primeira etapa de mesclar Push the button Avançar. segunda etapa de mesclar Push the button Consolidar Agora. terceira etapa de mesclar The merge is completed. quarta etapa de mesclar
  7. If all went well, the final state of the repository will be like this. You can see that we have the branch default occurring twice. Where the branch velhodefault is the link between them. estado final do repositório

Feel free to clone the repositories Old man and the New, and do their experiments.

  • Sorry for the delay @Marcos, but in step 2, I remove the file from the Velhor repository (Ctrl+x) and paste it in the new repository, but it does not appear in the "Detect Renames", even lowering the similarity. What can I do? Both are on the same basis: C: old - c: new

  • I usually forget to press the "Search for renames" button. Because the slider does not update automatically.

  • Even pressing the button does not "find" change @Marcos Zolnowski

  • I get it, you’re putting in the new directly. It needs to be in the old repository, imitating how it is in the new.

  • Because at this stage, we are changing the old repository, only in the next steps we will send the old contents to the new repository.

  • Even if I do in the old does not identify, it shows that it has been removed and is being added another, even if I select the 2, or one or the other, does not appear in the "Search Renames". (I have the latest version of Tortoisehg installed)

Show 2 more comments

2

You can use the extension Convertextension to export only that file from the first repository into a new temporary repository, then use hg pull -f to import the new repository into the target repository. Create a filemap file for Convertextension

touch myfilemap

Add the line to your content:

include caminho/para/arquivo

Then type:

hg convert caminho/para/arquivo/original caminho/para/arquivo/destino --filemap "myfilemap"

to create the temporary repository. Then, in the target repository, type:

hg pull -f caminho/para/temporario

to pull this file with its history. This will create a new HEAD. Use

hg merge

for merge it with the HEAD of your target repository.

  • Sorry it took so long to execute the command hg convert ... passing the filemap as said is giving this return: "Number o ® a Mercurial file", can help me?

  • Created the filemap file? I modified the answer a little to make it easier to understand

  • I’m in a Windows environment, I don’t understand exactly where to create the myfilemap, then what I did was: I created a temporary repository, I created a myfilemap file at temp root, added the inside include, Then when typing the command convert returns the above mentioned message, this in any of the 3 points

  • @David Sorry, I didn’t see your comment at the time. Managed to resolve?

  • Not yet @Marcos Regis, a friend and I studied the extension along with the step-by-step you did, and we couldn’t

  • I didn’t really take into consideration that it could be Windows and also explained how to make a single file and not a directory. Maybe it’s simpler to try this on some Linux (like a Live CD), push and then pull through Windows.

  • It’s going to be a little slow, but I’ll try. Thank you.

Show 2 more comments

1

I don’t use Tortoise, but I use GIT and VSTS and I’ve been through something similar.

I decided to create a new Branch of the project in a different path, and this new Branch became the main one. So we start working with the new way.

After all the commit's made, we delete the original/old folder on the developers' machines, as the versions continue on the server.

  • It’s also possible to do this with Mercurial, but if you do it this way we lose the entire Commit History, and that’s what we don’t want. Thank you.

  • @David, you shouldn’t miss it, because Branches upload the commit history. At least in VSTS it creates pointers that show where the sources of the new Branch came from and then the versions.

  • So @Thiago Lunardi, in Mercurial when we create a new branch and move the files from place he considers that we are removing these files and adding new ones. When executing the Command 'thg log file' we have the list of file changes and this we do not want to lose, because we know what was done in each commit because it is connected to an OS.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.