Make a TFVC Shelveset into a git commit
This post belongs in an earlier time, but I’m repatriating (read: burning) a load of old content from a work wiki and I thought some poor soul out there on the web might still need help with migrating from TFVC to git 🙏
Say you are trying to take a set of changes made to a TFVC/TFS repository and apply those changes to a git repository.
You could try and use tf diff /format:unified
but it produces garbage. Here is another way:
Part 0. Have a shelveset targeting Main
To create a shelveset of changes that apply to $/MyProject/Main
:
- Start a Merge of e.g. CoolFeature → Main,
- Instead of Checking In the changes to Main, Shelve them instead
- Abort the merge
- Undo All
Part 1. TFS Shelveset into patch file
We are going to temporarily set up a git repo in the checked-out TFS folder just to allow us to generate a diff using git diff
. Here we go:
- Have a pre-existing shelveset of changes that apply to
$/MyProject/Main
- Go to
D:/TFS/MyProject/Main
- Revert to clean status (Undo all)
- Add a .gitignore file (like the Visual Studio exemplar from the GitHub gitignore repo)
git init
git add -A
git commit -m 'Original'
- Unshelve the shelveset
git diff > cool-feature.patch
Part 2. Apply patch file to git repo
- Copy the patch file to near the actual git repo (i.e. one level up in
/d/git
) - Go into the directory of the git repo
- Check out the existing or new branch where the patch is going to apply
git checkout -b cool-feature-changes
git apply ../cool-feature.patch
- Then commit and push the changes to the remote git branch:
git add -A
git commit -m 'CoolFeature hanging changes'
git push -u origin cool-feature-changes
Part 3. Repeating this for more changes/other branches
- Go to
D:/TFS/MyProject/Main
- Revert to clean status (Undo all)
- .git and .gitignore will be left alone
- Unshelve your next set of changes
git diff > other-changes.patch