After git-tfs clone of two TFS stores, how to merge?

250 views
Skip to first unread message

Richard Wood

unread,
Jul 10, 2018, 8:41:33 AM7/10/18
to git-tfs-dev
Hi all,

I am investigating the best way of moving from TFS to GIT.

git-tfs works lovely for me, but there is a complication. We have an old and a new TFS server, with the history split between them :(


Our company had to move to a different domain, and so we created a new TFS server on the new domain, did a TFS Get Latest from the old TFS server, and a TFS Checkin on the new TFS server. (we didn't have enough time to research how to migrate the TFS database properly, so this simple solution was chosen)


Both TFS servers are still up and running.


So we have:-

Old TFS server has all history upto Dec 2016.
New TFS server has all history FROM Dec 2016.


I can clone each TFS server into its own local GIT repo no problem, branches, history, all lovely.


Is there any way I can merge the two together? Either at the git-tfs clone stage, or later on using git?


In the cloned git repo from the old TFS server I have tried to manually update the config file, updating the TFS 'urls' to point to the new TFS server and adding 'legacy-urls' that points to the old TFS server, but 'git-tfs fetch' does nothing, and 'git-tfs branch --init --all' fails with
Tfs branches found:
- $/Code/Features/AgX2.19
=> Working on TFS branch : $/Code/Features/AgX2.19
Branches to Initialize successively :
-$/Code/Features/AgX2.19 (312)
The name of the local branch will be : Features/AgX2.19
error: an error occurs when initializing the branch. Branch is ignored and continuing...
=> Working on TFS branch : $/Code/Dev

warning: Some Tfs branches could not have been initialized:
- $/Code/Features/AgX2.19

Please report this case to the git-tfs developers! (report here : https://github.com/git-tfs/git-tfs/issues/461 )
warning: Some Tfs branches could not have been initialized or entirely fetched due to errors:
- $/Code/Features/AgX2.19
   =>error:error: Couldn't fetch parent branch


Please report this case to the git-tfs developers! (report here : https://github.com/git-tfs/git-tfs/issues )



Thanks,
Richard Wood

Philippe Miossec

unread,
Jul 10, 2018, 8:47:55 AM7/10/18
to git-t...@googlegroups.com
Once you cloned the 2 histories, you should have 2 repositories.

Then:
1. In one of the repo, add a remote toward the other repo and fetch (you should have the 1 histories disconnected)
2. Use "git grafts" (https://git.wiki.kernel.org/index.php/GraftPoint) to connect the good commits together
2b. Look a the history to see if it suits you (return at step 2. until you're not satisfied)
3. Use "git filter-branch" to make the grafts definitive
4. Your history should be ok

--
You received this message because you are subscribed to the Google Groups "git-tfs-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to git-tfs-dev...@googlegroups.com.
To post to this group, send email to git-t...@googlegroups.com.
Visit this group at https://groups.google.com/group/git-tfs-dev.
For more options, visit https://groups.google.com/d/optout.

Richard Wood

unread,
Jul 10, 2018, 1:38:14 PM7/10/18
to git-tfs-dev
Thanks for your help.

Did this and at stage 2b the history (for the repo and file history) looked great.

After step 3 every checkin from the newer repo was duplicated into 'master' and 'original/refs/heads/master' branches.

Before step 3 I did use GIT Extensions to view the history, and in "Remote Repositories", in the "Default pull behaviour" tab I "Update(d) all remote branch info" which seemed to pull the remote across, and I set master in the remote repo to be the 'default merge with' for the local master. I suspect this messed something up so will try again without me doing this (as I'm happy the steps produced the result I wanted, upto step 2a)

The relevant parts of GITs config file look like this:-
[tfs-remote "default"]
repository = $/Code/Dev
[remote "oldrepo"]
url = D:\\temp\\OldDW-Git\\.git
fetch = +refs/heads/*:refs/remotes/oldrepo/*
[branch "master"]
remote = oldrepo
merge = refs/heads/master



Cheers,
Richard Wood

Richard Wood

unread,
Jul 11, 2018, 12:14:20 PM7/11/18
to git-tfs-dev
Ok got this to work now.

* Attached older repo to newer repo as a remote.
* git fetch old remote repo
* git checkout -B master oldrepo/master
* git rev-parse --verify master
Note the ID
* git checkout -B master tfs/default
* git rev-list master | tail -n 20
I didn't want the first checkin in the newer repo to be linked to the head of the old, I wanted to skip all the checkins where I added all code into newer repo, so the ID was the 8th or 9th one, hence getting IDs for the first 20 checkins. Pick the correct ID.
* git replace "new ID" "old ID"
* git filter-branch --tag-name-filter cat -- --all
Needs --all to include the branches in the newer repo otherwise they are not processed and will be removed.
* git for-each-ref --format="%(refname)" refs/original/
Then for each filename the above produced, view file and get the ID from it and...
* git update-ref -d <filename> <ID>


Cobbled together from Phillipes help and here
and here



Cheers,
Richard
Reply all
Reply to author
Forward
0 new messages