Skip to content

Instantly share code, notes, and snippets.

@saschazepter
Forked from amura2406/MigrateSVNtoGIT.md
Created November 7, 2024 15:49

Revisions

  1. @amura2406 amura2406 created this gist Aug 23, 2016.
    59 changes: 59 additions & 0 deletions MigrateSVNtoGIT.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,59 @@
    ## Install `svn2git`.
    On all systems you can install as a Ruby `gem` if you already have Ruby and Git installed.
    ```sh
    sudo gem install svn2git
    ```

    ## Checkout SVN Repo
    Checkout the latest SVN Repository of the project you want to convert.
    ```sh
    svn co --username <your_name> https://svn.server.com/repository/trunk
    ```

    ## Map Authors (Optional)
    Prepare an authors file so `svn2git` can map SVN authors to Git authors. If you choose not to create the authors file then commits will not be attributed to the correct Git user. Some users may not consider this a big issue while others will want to ensure they complete this step. If you choose to map authors you will be required to map every author that is present on changes in the SVN repository. If you don't, the conversion will fail and you will have to update the author file accordingly. The following command will search through the repository and output a list of authors.
    ```sh
    svn log --quiet | grep -E "r[0-9]+ \| .+ \|" | cut -d'|' -f2 | sed 's/ //g' | sort | uniq
    ```
    Use the output from the last command to construct the authors file. Create a file called `authors.txt` and add one mapping per line.
    ```
    janedoe = Jane Doe <janedoe@example.com>
    johndoe = John Doe <johndoe@example.com>
    ```

    ## Convert to Git format
    There are several way to convert the current project to Git format.

    1. The svn repo is in the standard layout of (trunk, branches, tags) at the root level of the repo.
    ```sh
    svn2git http://svn.example.com/path/to/repo --authors /path/to/authors.txt
    ```
    2. The svn repo is **NOT** in standard layout and has only a trunk at the root level of the repo.
    ```sh
    svn2git http://svn.example.com/path/to/repo --trunk trunk --nobranches --notags --authors /path/to/authors.txt
    ```
    3. The svn repo is **NOT** in standard layout and has no trunk, branches, or tags at the root level of the repo. Instead the root level of the repo is equivalent to the trunk and there are no tags or branches.
    ```sh
    svn2git http://svn.example.com/path/to/repo --rootistrunk --authors /path/to/authors.txt
    ```

    There are still several ways and can be refer to [this](https://github.com/nirvdrum/svn2git) link.

    ## Create Git Project
    Create a new Git project, where you will eventually push your converted code. Copy the SSH or HTTP(S) repository URL from the project page. Add the GitLab repository as a Git remote and push all the changes. This will push all commits, branches and tags.

    Add global config if you want
    ```sh
    git config --global user.name "John Doe"
    git config --global user.email "john.doe@gmail.com"
    ```

    Push the repo to remote server
    ```sh
    cd existing_folder
    git init
    git remote add origin git@gitserver:<group>/<project>.git
    git add .
    git commit
    git push -u origin master
    ```