-3

I am trying to migrate from SVN to git on windows by downloading the svn2git.sh script file and using the following command.

sh svn2git.sh [ProjectName] [SVN Repo link] [SVN Rev (Probably 0)] [Stash Repo Link]

I am new to this and very confused between git-svn and svn2git usage. Can anyone suggest me the steps for svn to git migration using svn2git tool?

2
  • Which svn2git.sh are you using? I have found more than one in my google searches. Could you give a link to the one you are using? Commented May 1, 2015 at 14:25
  • Hmm... I seem to be unable to load that web page Commented May 1, 2015 at 15:30

3 Answers 3

1

I created a script for svn to git migration. This script migrates the svn repo to git along with all it's tags and history maintained.

Pre-requisites : Make sure GIT and SVN are installed on your machine before moving ahead with the migration.

Description for Variables used

SVN_REPO_LINK : http link to where you svn repo is hosted

GIT_REPO_NAME : the name that you want to give to you new git repo

GIT_REPO_LINK : link to your git server where you want to host the repo. [It is basically a GIT remote that you would want to add]

Authors File : In svn the commits are associated with the username only, but in git repository email address is also required besides the username. Inorder to maintain the svn commits in git, user emails are are needed. This file serves that purpose. The format of the file is as follows :

svn user name = Name <email>

Helen_david = Helen David <[email protected]>

RobinR = Robin Rose <[email protected]>

Script

git svn clone --stdlayout --prefix 'svn/' -A authors.txt $SVN_REPO_LINK $GIT_REPO_NAME
cd $GIT_REPO_NAME

git for-each-ref refs/remotes/svn --format="%(refname:short)" | sed 's#svn/##' | grep -v '^tags'| while read aBranch; do git branch $aBranch svn/$aBranch; done
git branch -d trunk 
git for-each-ref refs/remotes/svn/tags --format="%(refname:short)" | sed 's#svn/tags/##' | while read aTag; do git tag $aTag svn/tags/$aTag; done
git remote add origin $GIT_REPO_LINK
git push -u --all origin
git push --tags origin

Now your repository is migrated along with all it's tags,branches and history.

Sign up to request clarification or add additional context in comments.

1 Comment

but without the externals ?
0

I had to migrate from SVN to git, and I found a really useful tutorial in atlassian. It shows you step by step how to migrate to git, in fact there is a svn-migration-scripts.jar that helps you with the process and this preserve your tags and branches, this is the link: https://www.atlassian.com/git/tutorials/migrating-overview.
And at the end you don't need to create a bibucket account, you can use github. Some of the command line changed in my case, for example I had to authenticate with user and pass when I created the authors.txt in convert step - Standard SVN layouts, so I added the user name at the end, more info in https://bitbucket.org/atlassian/svn-migration-scripts/src

 java -jar  <your path>/svn-migration-scripts.jar authors https://<svn_repo>/<project>/ <username> 

I skipped some of the steps, for example Synchronize process- Update the authors file, Automatically generating Git authors, Fetch the new SVN commits, Synchronize with the fetched commits, Clean up the Git repo (again), because in my case I did't need to commit in svn during the transition. It depends if you are working with more developers or not, and how fast you get use to git.

I also had to configure the ssh-key in the repo just in case that you need it. https://help.github.com/articles/generating-ssh-keys/

I hope this help you

Comments

-2

Migration Guide: Migrating an SVN Project to GitLab with history, excluding authors. Keep it simple. Later, permissions can be adjusted in the Git repository.

  1. Clone SVN repository:

    git svn clone svn-repository-url

  2. Navigate to Project Directory:

    cd cloned-project-folder

  3. Rename Branch:

    git branch -m main

  4. Create .gitignore file:

    touch .gitignore

  5. Add Files/Folders to .gitignore:

    #Modify .gitignore file to include files/folders you want to ignore.

  6. Stage Unwanted Files/Folders for Deletion:

    git rm --cached unwanted-file-name

    git rm -r --cached unwanted-folder-name

  7. Stage Changes:

    git add .

  8. Commit Changes:

    git commit -m "Initial migration from SVN to GitLab"

  9. Add GitLab Remote:

    git remote add origin gitlab-remote-repo-url

  10. Verify Remote:

    git remote -v

  11. Push to GitLab:

    git push -u origin main

Replace placeholders like svn-repository-url, cloned-project-folder, gitlab-remote-repo-url, unwanted-file-name, and unwanted-folder-name with the appropriate values for your project.

3 Comments

This definitely does not migrate history.
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
Kindly check the answer again. Due to some special characters, some words were not visible. I have tried this solution for my project as well, and it worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.