SVN projects are migrated to Git, and SVN branches and complete commit records are kept

scenario

In the group, we need to move the code from SVN server to Git.

The first step is to use git SVN to transform git repository

Second, commit the Git repository to the Git server.

It was originally a very happy event, but the brave met with trouble when buying equipment. When I was working on Git SVN, the environment made a mistake. I’ll start with Windows.

Note: If you want to keep the SVN branch and complete submission records, you need to get the SVN server permission, and the corresponding SVN user name and Git user name and mailbox. Here I am the administrator of the SVN project created in the SVNBucket to migrate to my own Git above the tutorial. If you don’t have permission or too much trouble, please turn to the last word of violent migration.

First, preparation

Pull the project down first

svn checkout svn://svnbucket.com/candy_girl/candy_test/
Copy the code

Create a users.txt file in the project directory that contains mappings in the following format:

schacon = Scott Chacon <[email protected]>
selse = Someo Nelse <[email protected]>
Copy the code

Get a list of author names used by SVN. You can run this

svn log --xml --quiet | grep author | sort -u | \ perl -pe 's/.*>(.*?) <. * / $1 = / 'Copy the code

Git SVN clone = Git SVN clone = Git SVN clone = Git SVN clone = Git SVN clone

cp users.txt .. /Copy the code

2. Run the git SVN clone command to pull the SVN library

Git SVN clone SVN library address –authors-file=users. TXT –no-metadata –prefix “” -s Target folder name

/ / my project command git SVN clone svn://svnbucket.com/candy_girl/candy_test/ -- the authors - the file = users. TXT - no - metadata -- prefix "" -s candy_test_gitCopy the code

–authors-file specifies an author file, and –no-metadata removes git-svn-id

Note: When you want to mirror a commit from a Git repository back to the SVN repository, do not add the –no-metadata option if you want to preserve metadata

3. Handle tag

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
Copy the code

Function: Convert a tag directory in the tags directory of the SVN library to a Git tag

Fourth, processing 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
Copy the code

Description: Convert branches under SVN library branches to Git branches

5, Processing PEG-REVISIONS (Optional)

for p in $(git for-each-ref --format='%(refname:short)' | grep @); do git branch -D $p; done
Copy the code

Some branches have the suffix @xxx (where XXX is a number)

Delete unnecessary trunk branches (master and trunk duplicate)

git branch -d trunk
Copy the code

Add remote repository address to git repository

Git remote add Origin Specifies the remote repository addressCopy the code

Eight, push to the remote warehouse

git push origin --all
git push origin --tags
Copy the code

The migration of violence

Is also a common way of migration, the evening before someone from work submitted after the merger to trunk, main migration to git, the next day everyone git pull before development, if branch of SVN and development need to continuously develop, cut a new branch in the git, moved the SVN branch code and git branch, branch switch continue to develop.