gitversion-controlmigrationtfvcgit-tfs

Migrate subfolder from TFVC repository to git


I am trying to migrate a single Core subdirectory from a TFVC repository into a git repository. The source is used in multiple projects and the other subdirectories are never used but need to be fetched when cloning the repository. They are also conceptually unrelated.

The repo layout looks something like this:

$Project/Repo1/Main
$Project/Repo1/dev/branch1
    +branch2
    ...
    +branchN
$Project/Repo1/release/RelBranch1
...

and each branch has a flat folder structure, with the important Core directory and loads of other unused directories (these are not empty, just unrelated to the Core directory):

<branch-folder>
|-Core
|-Other
|-Other2
|-...
|-OtherN

The only way I see this happening is to migrate the source to git using git-tfs, then remove the other directories in the first commit. This seems clumsy, any investigation of the history of the repo will bring back the unwanted directories? Is there a better way of achieving the desired repo structure?

The new layout in git should contain only the Core subdirectory of the repo with all the branches and as much history as possible. Fortunately, in all cases, there are no commits which reference files from both Core directory and any of the Other directories.


Ideally, I would like to merge several subdirectories from different TFVC repository into a single git repo, but I have focussed on the core problem in this question. At present, I'll be migrating each to a separate repo and then using submodules to glue them together.


Solution

  • You can do this in 2 steps, first perform the migration with the git-tfs tool. You will need to select a minimum changeset for the migration. If you want to include a specific branch, you should include at least the changeset before the branching:

    # make a new directory and move into it
    
    git tfs clone $TeamURL $TFSProjectToClone .  --changeset=$MinimumChangeset --branches=auto
    git tfs verify
    
    

    Then you can filter the repository with git filter-repo, the readme.md has an example for how to filter the repo for a specific subdirectory.

    git filter-repo --path src/
    
    # Add remote and push
    

    Where src is the only directory to keep in the repository. You can also use this tool to rename the directories and the tags.