Help Center> CodeArts Repo> User Guide> Old Version> Repository Migration> Migrating an SVN Repository to CodeHub
Updated on 2023-07-25 GMT+08:00

Migrating an SVN Repository to CodeHub

Migration Method: Import on the Git Bash Client

  1. Obtain committer information of the SVN repository.

    1. Use TortoiseSVN to download the repository to be migrated to the local host.
    2. Go to the local SVN repository (KotlinGallery in this example) and run the following command on the Git Bash client:
      svn log --xml | grep "^<author" | sort -u | \awk -F '<author>' '{print $2}' | awk -F '</author>' '{print $1}' > userinfo.txt

      The userinfo.txt file is generated in the directory.

    3. Open the userinfo.txt file. You can view the information about all committers who have committed code to the repository.
    4. Git uses an email address to identify a committer. To better map the SVN repository information to a Git repository, create a mapping between the SVN and Git usernames.

      Modify the userinfo.txt file. Each line should be in the format of svn_author = git_author_nickname <email_address>.

  2. Create a local Git repository.

    1. Create an empty Git repository directory on the local host, and copy the userinfo.txt file obtained in 1 to the directory.
    2. Start the Git Bash client in the directory and run the following command to clone a Git repository:
      git svn clone <svn_repository_address> --no-metadata --authors-file=userinfo.txt --trunk=trunk --tags=tags --branches=branches

      The following table lists parameters in the command. Set the parameters as required.

      Parameter

      Description

      --no-metadata

      Prevents the Git from exporting useless information contained in the SVN.

      --authors-file

      File that maps all SVN accounts to Git accounts

      --trunk

      Main development project

      --branches

      Branch projects

      --tags

      Tags

      After the command is executed, a Git repository is generated locally.

    3. Run the following commands to go to the KotlinGallery folder and verify the current Git repository branch structure:
      cd KotlinGallery
      git branch -a

      As shown in the preceding figure, all SVN directory structures are successfully migrated in the form of Git branches.

  3. Correct local branches.

    In 2, the git svn clone command is used to save the tags folder in the SVN repository as a branch, which does not comply with the Git usage guidelines. Therefore, before uploading tags to the remote repository, adjust the local branches to comply with the Git usage guidelines.

    1. Go to the local Git repository and run the following commands on the Git Bash client to change the tags branch to appropriate Git tags:
      cp -Rf .git/refs/remotes/origin/tags/* .git/refs/tags/
      rm -Rf .git/refs/remotes/origin/tags
      git branch -a
      git tag

    2. Run the following commands to change the remaining indexes under refs/remotes to local branches:
      cp -Rf .git/refs/remotes/origin/* .git/refs/heads/
      rm -Rf .git/refs/remotes/origin
      git branch -a
      git tag

    3. Run the following commands to merge the trunk branch into the master branch, and delete the trunk branch:
      git merge trunk
      git branch -d trunk
      git branch -a
      git tag

  4. Upload the local code.

    1. Set the SSH key of the repository by referring to Overview.
    2. Run the following commands to associate the local repository with the CodeHub repository and push the master branch to the CodeHub repository:
      git remote add origin <Codehub_repository_address>
      git push --set-upstream origin master

      After the push is successful, log in to CodeHub and view the master branch of the repository on the Branches tab page.

    3. Run the following command to push other branches from the local computer to CodeHub:
      git push origin --all

      After the push is successful, the r1.1_hotfix branch is added to the repository, as displayed on the Branches tab page.

    4. Run the following command to push tags from the local host to CodeHub:
      git push origin --tags

      After the push is successful, the tags r1.0 and r1.1 are added to the repository, as displayed on the Tags tab page of CodeHub.