Move some projects from a user account to another

2019-07-14 11:36发布

问题:

I am going to change my work company, but I will continue working on the same projects. I have some projects on Azure DevOps with Git and another one with TFVC. I have used these source control tools integrated on Visual Studio, I have never used the console commands.

I want to "copy" the source code with all changes of some projects (not all projects) from one account to another. And if it is possible to migrate TFVC to Git. How can I do it?

回答1:

First of all, migrate the TFVC code to Git with the git-tfs tool.

When your all code in Git you can move the code easily to another project:

1) Clone the repository to a local folder.

2) Go to TFS/Azure DevOps and create a new Git repository.

3) Push the local repo to TFS/Azure DevOps repo.

The best way to do it is with Command Line:

1) git clone old-repo-url

2) Create the new repo from TFS/Azure DevOps portal.

3) git remote add origin new-repo-url

git push -u origin --all



回答2:

TFVC

TFVC is notoriously hard to migrate from one server to the other. There are some tools out there that can help, but TFVC->TFVC is hard to do right. Due to the fact that you can do things in TFVC that aren't possible in Git, it is not always possible to carry over **all* history and **all* branches. In general, though, it's enough to transfer the main branch with some history.

With that caveat, fortunately, TFVC->Git is a lot easier. From your current Azure DevOps account, choose the Import Repository option:

You can specify a single branch to import with up to 180 days of history. For most projects that's more than enough. Using this route it's not possible to import multiple branches, so you'll need to integrate your work into a single branch first in case you have in-progress items.

This will convert your TFVC branch into a Git repository. You can execute this as many times as you want to import different branches and from different TFVC repositories until all your work is in Git.

Git

There are multiple ways to move a Git repository from one system to another, but since you're using Azure DevOps, you can use the same Import Repository option to let Azure Repos import the data from the old account straight into a new one.

First, you'll need to create a new target account (or use your existing personal account if you have one). Then use the same Import Repository option, but this time from your new account.

Enter the Clone URL for the repository you want to move over and provide your Git Credentials or a Personal Access Token:

This will automatically pull in all your code, branches, tags etc into your target account and into a new Git repository. Execute this sequence as many times as you have Git repos.


The command line way

You can also perform the same steps using the commandline:

Git

To clone a repo for migration use a fresh clone and specify the --mirror option:

git clone https://dev.azure.com/{Org}/{Project}/_git/{Repo} --mirror

Then push everything into a new, empty, git repository on the new account:

git push --mirror https://dev.azure.com/{NewOrg}/{NewProject}/_git/{NewRepo}

TFVC

For TFVC you have tools that can import a TFVC branch into a git repository with optional history as well. git tfs allows you to perform such an export:

git tfs clone http://your-tfs-server:8080/tfs/your-collection $/your-tfvc-repo

This process will take some time to import your changesets into the local git repo. Afterwards, you can push the resulting Git Repository into the new target Azure DevOps project:

git remote add target https://dev.azure.com/{NewOrg}/{NewProject}/_git/{NewRepo}
git push --all target