Migrating an SVN Repository to CodeHub
Migration Method: Import on the Git Bash Client
- Obtain committer information of the SVN repository.
- Use TortoiseSVN to download the repository to be migrated to the local host.
- 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.
- Open the userinfo.txt file. You can view the information about all committers who have committed code to the repository.
- 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>.
- Create a local Git repository.
- Create an empty Git repository directory on the local host, and copy the userinfo.txt file obtained in 1 to the directory.
- 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.
- 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.
- 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.
- 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
- 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
- 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
- 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:
- Upload the local code.
- Set the SSH key of the repository by referring to Overview.
- 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.
- 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.
- 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.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot