1
votes

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.

1
I know nothing about TFS but I can tell you that if the directories are empty, git won't hold them. In git what people tend to do is to add a readme.txt file explaining why the file is there and move on. Even a hidden file would do.eftshift0
@eftshift0 Thanks for your input. None of the directories I am working with are empty, they all contain source.Mansoor

1 Answers

2
votes

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.