Wednesday, December 20, 2023

SVN to Git to TFS

1. install Git-SVN bash for windows. https://git-scm.com/download/win (64-bit Git for Windows Portable.)

2. From cmd to launch MinGW64

    start "" "C:\Admin\PortableGit-2.43.0-64-bit.7z\bin\bash.exe" 

3. From MinGW64

    mkdir -p ~/GitMigration

4. create a user transformation file

svn log http://dshsutlcy3dut02.dshs.wa.lcl:9083/svn/DSHS-CA/sacwis-web/branches/DCYF/Sprint-Active --quiet | grep -E "r[0-9]+ \| .+ \|" | cut -d'|' -f2 | sed 's/ //g' | sort | uniq > svn-authors.txt

jdoe = John Doe <john.doe@gmail.com>

esmith = Emma Smith <emma.smith@gmail.com>

first column is SVN user and 2nd column is Git user

5. create an empty git repository from TFS and copy the git command for http

6. git svn clone http://dshsutlcy3dut02.dshs.wa.lcl:9083/svn/DSHS-CA/sacwis-build-xml/branches/DCYF/Sprint-Active/sacwis-web-tfs-build-xml SVNGit --authors-file=../authors-transform.txt -r 9750:HEAD

   check out svn to a git folder

7. clean up

   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;

8. create a repository on Git server (etc. devopts) (this is an optional step if you want to check in Git)

    
        git remote add origin http://dshsutoly3dut06:8080/tfs/CATS/FamlinkClassic/_git/sacwis-git

git remote set-url origin https://weiwang0944@dev.azure.com/weiwang0944/pltest1/_git/migration

git push origin --all;

git push origin --tags;

     git push origin master:Sprint-Active (push a particular local branch to a particular remote                         branch git push origin local:remoe)

    
        (Cannot determine the organization name for this 'dev.azure.com' remote url. ensure             the credential.usehttppath configuration value is set, or set the organization name as the user in the remote url '{org}@dev.azure.com'.) 

git config --global credential.useHttpPath true (for SSO login issue above)

git remote add origin https://weiwang0944@dev.azure.com/weiwang0944/pltest1/_git/migration

reset origin if needed


--------------------------------------------------------------------------------------------------------------------

install git-tf

cd to SVNGit on cmd

1. set origin

    git-tf configure http://dshsutoly3dut06:8080/tfs/CATS $/FamlinkClassic/sacwis-build-xml/GitTFS

2. check in 

    git-tf checkin --deep


----------------------------------------------------------------------------------------------------------------------

https://medium.com/codex/how-to-migrate-svn-to-git-b625a21575b2

I was recently working on a migration project which involved migrating our codebase from SVN to GitHub. After a few trials and errors and plenty of hours searching the web for best practices, I finally managed to develop a system that did not cause any tears during the process and I thought it would be nice to share it with you.

I have broken down this migration process into 4 simple steps:

  1. Prepare your environment
  2. Convert your SVN repository to a local git repository
  3. Convert any large files to lfs objects (if needed)
  4. Push the new git repository to GitHub

Prepare your environment

On your local machine create a GitMigration folder which will host your new git repo: mkdir -p ~/GitMigration

In another command line update the SVN repo to make sure that you have the latest revisions. It would be also wise to inform your team that you are starting the migration and no more commits will be allowed to be pushed to SVN until the migration process is complete.

Once that is done you will need to create an authors.txt file. This will map the SVN usernames to the desired Git usernames in the following format:

jdoe = John Doe <john.doe@gmail.com>
esmith = Emma Smith <emma.smith@gmail.com>

If you don’t want to find all the authors in the SVN manually you can pull the data from the SVN repository using the following command, just make sure that the final format follows the same structure as above:

svn log -q | awk -F '|' '/^r/ {gsub(/ /, "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors.txt

Convert your SVN repository to a local git repository

If you want to only migrate commits from a certain time period, you will need to locate the revision number in the SVN repo. To do this execute the following command in the svn repo folder:

svn log -r {YYYY-DD-MM}:HEAD --limit 1

Within the GitMigration folder execute the following command:

git svn clone <svn-repo>/<project> <git-repo-name> --authors-file=authors.txt -r <revision-number>:HEAD

Where <svn-repo> is the URI of the SVN repository that you want to migrate, <project> is the name of the project that you want to import, and <revisions-number> is the revision number that you want to migrate from (if needed). The<git-repo-name> is the directory name of the new Git repository. This process might take a while, depending on the size of the SVN commits.

Now comes the clean-up, moving the tags and any remote refs to local branches. To move the tags to proper Git tags execute the following within the git repo directory:

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

Next, move any references under refs/remote and turn them to local branches

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;

Convert any large files to LFS objects

GitHub has a file limit of 100MB, anything over that size will be refused to be pushed into GitHub. This is where Git Large File Storage (LFS) comes in. Git LFS replaces any large files with text pointers inside Git while storing the file contents on a remote server. There are many benefits to using LFS such as

  • Large file versioning
  • More repository space
  • Faster cloning and fetching
  • Same Git workflow
  • Same access controls and permissions

To find out how many files that are above the 100MB limit run the following command:

git lfs migrate info --everything --above=99MB

this will print out information about the different file types in your repo that are above the 99MB mark (as shown below).

To convert the files to LFS file objects run the following command:

git lfs migrate import --everything --above=99MB

This will rewrite the history of the git repo that contained any files that were above 99MB and convert them to LSF objects.

Push the new git repository to GitHub

The final step is to add the remote git server and push the changes.

git remote add origin git@my-git-server:myrepository.gitgit push origin --all;git push origin --tags;

And that’s it! Congratulations, you have migrated your SVN repo into Git. The next step is to inform your team that the migration is complete and provide them access to the new remote git server.

----------------------------------------------------------------------------------


https://blog.simontimms.com/2013/04/02/importing-a-git-repository-into-tfs/

Now drop into the git repository you want to push to TFS and enter

git tf configure http://tfsserver:8080/tfs $/Scanner/Main

Wherehttp://tfsserver:8080/tfs is the collection path for your TFS server and$/Scanner/Main is the server path to which you’re pushing. This will modify your .git/config file and add the following:

[git-tf “server”] collection =http://tfsserver:8080/tfs serverpath =$/Scanner/Main

Your git repository now knows a bit about TFS. All you need to do now is push your git code up and that can be done using

git tf checkin --deep

This will push all the commits on the mainline of your git repo up into TFS. Without the ““deep flag only the latest commit will be submitted.

There are a couple of gotchas around branching. You may get this error:

git-tf: cannot check in - commit 70350fb has multiple parents, please rebase to form a linear history or use –shallow or –autosquash

You canflattenyour branches by either rebasing or by passing git-tf the ““autosquash flag which will attempt to flatten the branching structure automatically. I’m told that autosquashing can consume a lot of memory if there are a lot of commits in the repository. I have not had any issue but my repositories are small and my machine has 16GB of memory.

Now you have move all your source code over to TFS. Yay.

I’m not going to point out that if you keep git-tf around you can continue to work as if you have git and just push commits to TFS. That would likely be against your company’s policies

--------------------------------------------------------------------------------------------------------------

https://stackoverflow.com/questions/39478482/how-to-create-development-branch-from-master-on-github


Creating a git develop branch

You can list all of your current branches like this:

git branch -a

This shows all of the local and remote branches. Assuming you only have a single master branch, you'd see the following:

* master
  remotes/origin/master

The * means the current branch.

To create a new branch named develop, use the following command:

git checkout -b develop

The -b flag creates the branch. Listing the branches now should show:

* develop
  master
  remotes/origin/master

Changing branches

You shouldn't commit anything directly to the master branch. Instead do all your work on the develop branch and then merge develop into master whenever you have a new public release.

You are already in your develop branch, but if you weren't, the way to switch is as follows:

git checkout develop

That's the same way you create a branch but without the -b.

Making changes on develop

When making changes, add and commit as usual:

git add .
git commit -m "whatever"

The first time you push to your remote do it like so:

git push -u origin develop

The -u flag stands for --set-upstream. After the first time you only need to do it like this:

git push

Merging develop to master

Once your develop is ready to merge into master you can do it like so:

First switch to your local master branch:

git checkout master

To merge develop into master do the following:

git merge develop

Then push the changes in local master to the remote master:

git push

Done.

Deleting a branch

If you don't need the develop branch anymore, or you just want to delete it and start over, you can do the following:

Delete the remote develop branch:

git push -d origin develop

Then delete the local branch:

git branch -d develop

The -d means delete.

------------------------------------------------

git config --global user.name "John Doe"

git config --global user.email "johndoe@email.com"


.