My aim is to migrate my SVN stored project to Git in a one-way, one-shot migration, i.e. once it's done we use Git and dump SVN completely. To that end I'm trying to migrate the commit logs from v35.0 to latest (currently v49.0) of the application. The solution for application consists of about 20-30 projects, libraries, exes, etc...
The structure (and case) of my project in SVN is as follows:
There are other folders at the same level as Branches/Tags/Trunk, e.g. FeatureBranches, but they can all be ignored.
I run the following in my SVN trunk folder to get authors formatted correctly for Git:
svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors-transform.txt
I run the following command in Git Bash prompt in a new empty folder I created for the migration:
git svn init --prefix "" --no-metadata --trunk=Trunk --branches=Branches --tags=Tags https://my/svn/project/
[UPDATED 08/02] Then I edit the /.git/config file and remove branches line and replace the tags line with:
tags = Tags/35/*:refs/remotes/tags/*
tags = Tags/36/*:refs/remotes/tags/*
tags = Tags/37/*:refs/remotes/tags/*
tags = Tags/38/*:refs/remotes/tags/*
tags = Tags/39/*:refs/remotes/tags/*
tags = Tags/40/*:refs/remotes/tags/*
tags = Tags/41/*:refs/remotes/tags/*
tags = Tags/42/*:refs/remotes/tags/*
tags = Tags/43/*:refs/remotes/tags/*
tags = Tags/44/*:refs/remotes/tags/*
tags = Tags/45/*:refs/remotes/tags/*
tags = Tags/45/*:refs/remotes/tags/*
tags = Tags/46/*:refs/remotes/tags/*
tags = Tags/47/*:refs/remotes/tags/*
tags = Tags/48/*:refs/remotes/tags/*
tags = Tags/49/*:refs/remotes/tags/*
I then run the command:
git lfs install
I then copy into the folder a .gitattributes file containing the list of files to be tracked be Git LFS. I've made multiple attempts at this so I saved this file from a previous attempt. I'd used git lfs track commands previously. Similarly I copy in a .gitignore file and the authors-transform.txt file created by the earlier command.
Next I run:
git svn fetch --log-window-size=5000 -A authors-transform.txt
Then I go away for around 25 hours that it roughly takes and do something else, eat, sleep, more work etc..
I then run:
for t in $(git for-each-ref --format='%(refname:short)' refs/remotes/tags); do git tag ${t/tags//} $t && git branch -D -r $t; done
for b in $(git for-each-ref --format='%(refname:short)' refs/remotes); do git branch $b refs/remotes/$b && git branch -D -r $b; done
for p in $(git for-each-ref --format='%(refname:short)' | grep @); do git branch -D $p; done
git branch -d trunk
The final command above resulted in:
fatal: Couldn't look up commit object for HEAD
[UPDATED 08/02] I fire up SourceTree and point it at my folder and the horror unfolds. There is 1 branch called "trunk" and there are 50 tags. Only 1 of hte tags is correct - 35.0, the rest are all named after one of the solution project folders; some are almost identical except there is an @number after them, i.e. Fubar@1423, Fubar@1568
If this hadn't of all gone horribly wrong I would have run the following to complete:
$ git remote add origin <AzureDevOps git url>
$ git push origin --all
$ git push origin --tags
I'm a relative Git noob and so have been piecing things together from other colleagues and Git docs but I have to admit I have a big case of imposter syndrome and am totally lost at this point. If anybody has any ideas for commands or config I got wrong and what I should do to achieve my aim I would be most appreciative.
question from:
https://stackoverflow.com/questions/66050729/migrating-svn-project-to-git-branches-and-tags-coming-out-completely-wrong