We have just migrated from TFVC to Git and immediately we have a problem - how to cherry pick TFVC commits to Git?
Given
- TFVC branch
$/Alice
- TFVC branch
$/Bob
- Git repo with
$/Alice
migrated as thealice
branch and$/Bob
- as thebob
branch. - The TFVC history was not migrated, so the entire TFVC history of '$/Alice' is just one Git commit. The same is true for
$\Bob
.
Problem
Now we discover a TFVC commit in $/Alice
that was not merged to $/Bob
before the migration. Now after the migration we realize we need to have it in the bob
branch. Major bummer.
I am talking about a big change - many files. Hence diffing the files manually and copying over the changes is not very feasible. I need to automate the process as much as possible.
What I did so far
I figured I should create a patch for the TFVC changeset in question. So, here is the code (assuming I need to cherry pick commit 123):
$files = (tf changeset /noprompt 123 | sls '\$/') -replace '^[^$]+',''
$files |% { tf diff /version:C122~C123 /format:unified $_ } >> 123.diff
(I do it file by file, because it is much faster than running tf diff
with /r
flag)
Anyway, I get a patch file like this:
File: BackgroundJobTests\BackgroundJobTests.csproj
===================================================================
--- Server: BackgroundJobTests.csproj;115493
+++ Server: BackgroundJobTests.csproj;389742
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
===================================================================
File: BI\a8i\a8i.csproj
===================================================================
--- Server: a8i.csproj;342293
+++ Server: a8i.csproj;389742
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
...
A typical Git stash patch looks a bit differently:
diff --git a/Yogi.txt b/Yogi.txt
index 056fd9e..1f73d44 100644
--- a/Yogi.txt
+++ b/Yogi.txt
@@ -1 +1 @@
-yaba daba do
+yaba daba doo
diff --git a/hello.txt b/hello.txt
index ce01362..980a0d5 100644
--- a/hello.txt
+++ b/hello.txt
@@ -1 +1 @@
-hello
+Hello World!
And here I feel I need some guidance. Maybe I am doing it all wrong and there is an off-the-shelf solution for my pain. Or maybe I am in the right direction and all I need is a way to "fool" Git into accepting my patch as a stash patch. But devil is in the details, and I am lacking them.