Skip to content

Instantly share code, notes, and snippets.

@cbmeeks
Last active March 5, 2025 19:00
Show Gist options
  • Select an option

  • Save cbmeeks/f4e65f0435d91312d79447176e5812ba to your computer and use it in GitHub Desktop.

Select an option

Save cbmeeks/f4e65f0435d91312d79447176e5812ba to your computer and use it in GitHub Desktop.

Revisions

  1. cbmeeks revised this gist Mar 5, 2025. 1 changed file with 6 additions and 9 deletions.
    15 changes: 6 additions & 9 deletions svn2git.md
    Original file line number Diff line number Diff line change
    @@ -32,17 +32,11 @@ Save this file (e.g., ~/authors.txt).
    ## Clone the SVN Repository to a Local Git Repository

    Use git-svn to clone your SVN repository, converting its history into Git commits.
    Make sure you are in the _parent_ folder of your repo as the following command will create a new directory from whatever you put as <LOCAL_DIR>.
    Run the following command:

    ```bash
    git svn clone <SVN_REPO_URL> --stdlayout --authors-file=~/authors.txt <LOCAL_DIR>
    ```

    If you get an error, like the "authors.txt" cannot be found, then you can just remove it.
    You can use the following instead. Just make sure you are in the directory where you want to pull the SVN repo down.

    ```bash
    git svn clone <SVN_REPO_URL> --stdlayout
    git svn clone <SVN_REPO_URL> --stdlayout <LOCAL_DIR>
    ```

    - <SVN_REPO_URL>: The URL of your SVN repository (e.g., http://svn.example.com/repo).
    @@ -53,9 +47,12 @@ git svn clone <SVN_REPO_URL> --stdlayout
    For example:

    ```bash
    git svn clone http://svn.example.com/repo --stdlayout --authors-file=~/authors.txt my-git-repo
    cd ~/Projects
    git svn clone http://svn.example.com/repo --stdlayout my-git-repo
    ```

    You should now have a folder called "my-git-repo" that contains the repo.

    This process may take time depending on the size of your repository and the number of revisions.

    ## If your repo doesn't follow standard svn layout
  2. cbmeeks revised this gist Mar 5, 2025. 1 changed file with 13 additions and 11 deletions.
    24 changes: 13 additions & 11 deletions svn2git.md
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,14 @@
    # Create New Repopository in Bitbucket
    # How to Import SVN Repos into BitBucket

    ## Create New Repopository in Bitbucket

    _NOTE_, if you create an empty repo in Bitbucket, it will default to the "main" branch and create
    a .gitignore file. Normally, this would be OK. However, the .gitignore file will cause a conflict
    because the newly created repo will not be empty. You will need to pull then push.

    ### It is recommended to NOT create a .gitignore file by default and make sure the new repo is completely empty.

    # Prepare an Authors Mapping File (Optional but Recommended)
    ## Prepare an Authors Mapping File (Optional but Recommended)

    SVN stores only usernames for commits, while Git requires a name and email address for each author.
    To map SVN usernames to Git-compatible author details, create an authors.txt file:
    @@ -27,7 +29,7 @@ If you skip this step, git-svn will use the SVN username as both the name and em

    Save this file (e.g., ~/authors.txt).

    # Clone the SVN Repository to a Local Git Repository
    ## Clone the SVN Repository to a Local Git Repository

    Use git-svn to clone your SVN repository, converting its history into Git commits.
    Run the following command:
    @@ -56,7 +58,7 @@ git svn clone http://svn.example.com/repo --stdlayout --authors-file=~/authors.t

    This process may take time depending on the size of your repository and the number of revisions.

    # If your repo doesn't follow standard svn layout
    ## If your repo doesn't follow standard svn layout

    If your repo doesn't have the normal "trunk", "branch", "tag" folder structure, you will have to clone them a different way.
    Start by finding the folder structure:
    @@ -67,7 +69,7 @@ svn ls <SVN_REPO_URL>

    You should get a list of folders/files. If no "trunk" is given, then "/" is your trunk.

    ## Run git svn clone with custom paths
    ### Run git svn clone with custom paths

    ```bash
    git svn clone <SVN_REPO_URL> --trunk=<TRUNK_PATH> --branches=<BRANCHES_PATH> --tags=<TAGS_PATH> <LOCAL_DIR>
    @@ -81,15 +83,15 @@ Example (assuming "project" is a folder):
    git svn clone http://svn.example.com/repo --trunk=project my-git-repo
    ```

    # Navigate to the New Git Repository
    ## Navigate to the New Git Repository

    Once the cloning is complete, move into the new Git repository:

    ```bash
    cd my-git-repo
    ```

    # Clean Up Branches and Tags
    ## Clean Up Branches and Tags

    The git-svn tool imports SVN branches and tags as remote branches (e.g., remotes/origin/trunk, remotes/origin/tags/tag1).
    You’ll need to convert these into proper Git branches and tags.
    @@ -126,7 +128,7 @@ git branch -r -d origin/branch1

    Repeat for each branch you want to keep.

    # Add Bitbucket as a Remote
    ## Add Bitbucket as a Remote

    ### Link your local Git repository to the empty Bitbucket repository

    @@ -137,7 +139,7 @@ git remote add origin <BITBUCKET_REPO_URL>
    - <BITBUCKET_REPO_URL>: The URL of your Bitbucket repository (e.g., git@bitbucket.org:username/repo.git).
    - You can find this on the Bitbucket repository page under "Clone."

    # Push the Repository to Bitbucket
    ## Push the Repository to Bitbucket

    Push all branches and tags to Bitbucket:

    @@ -149,7 +151,7 @@ git push origin --tags
    - --all: Pushes all branches.
    - --tags: Pushes all tags.

    # Verify the Migration
    ## Verify the Migration

    Visit your Bitbucket repository in a browser to confirm that the commits, branches, and tags have been successfully migrated.
    Use git log locally to double-check the history:
    @@ -158,7 +160,7 @@ Use git log locally to double-check the history:
    git log
    ```

    # Additional Tips
    ## Additional Tips

    - Large Repositories: For very large SVN repositories, the git svn clone process can be slow.
    You can speed it up by specifying a revision range with -r (e.g., -r 1000:HEAD to start from revision 1000).
  3. cbmeeks revised this gist Mar 5, 2025. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions svn2git.md
    Original file line number Diff line number Diff line change
    @@ -6,8 +6,6 @@ because the newly created repo will not be empty. You will need to pull then pus

    ### It is recommended to NOT create a .gitignore file by default and make sure the new repo is completely empty.

    ### It is also recommended to use "master" as the default branch. Otherwise, you will have to remove "master" or "main" after import.

    # Prepare an Authors Mapping File (Optional but Recommended)

    SVN stores only usernames for commits, while Git requires a name and email address for each author.
  4. cbmeeks created this gist Mar 5, 2025.
    173 changes: 173 additions & 0 deletions svn2git.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,173 @@
    # Create New Repopository in Bitbucket

    _NOTE_, if you create an empty repo in Bitbucket, it will default to the "main" branch and create
    a .gitignore file. Normally, this would be OK. However, the .gitignore file will cause a conflict
    because the newly created repo will not be empty. You will need to pull then push.

    ### It is recommended to NOT create a .gitignore file by default and make sure the new repo is completely empty.

    ### It is also recommended to use "master" as the default branch. Otherwise, you will have to remove "master" or "main" after import.

    # Prepare an Authors Mapping File (Optional but Recommended)

    SVN stores only usernames for commits, while Git requires a name and email address for each author.
    To map SVN usernames to Git-compatible author details, create an authors.txt file:

    ```bash
    svnuser1 = FirstName LastName <user1@example.com>
    svnuser2 = Another Name <user2@example.com>
    ```

    You can generate a list of SVN authors by running:

    ```bash
    svn log <SVN_REPO_URL> --quiet | grep -E "r[0-9]+ \| .+ \|" | cut -d'|' -f2 | sed 's/ //g' | sort | uniq > authors.txt
    ```

    Edit the file manually to add names and email addresses.
    If you skip this step, git-svn will use the SVN username as both the name and email, which may not be ideal.

    Save this file (e.g., ~/authors.txt).

    # Clone the SVN Repository to a Local Git Repository

    Use git-svn to clone your SVN repository, converting its history into Git commits.
    Run the following command:

    ```bash
    git svn clone <SVN_REPO_URL> --stdlayout --authors-file=~/authors.txt <LOCAL_DIR>
    ```

    If you get an error, like the "authors.txt" cannot be found, then you can just remove it.
    You can use the following instead. Just make sure you are in the directory where you want to pull the SVN repo down.

    ```bash
    git svn clone <SVN_REPO_URL> --stdlayout
    ```

    - <SVN_REPO_URL>: The URL of your SVN repository (e.g., http://svn.example.com/repo).
    - --stdlayout: Assumes your SVN repo uses the standard trunk, branches, and tags structure. If it doesn’t, see the note below.
    - --authors-file=~/authors.txt: Path to your authors mapping file (optional).
    - <LOCAL_DIR>: The directory where the new Git repository will be created (e.g., my-git-repo).

    For example:

    ```bash
    git svn clone http://svn.example.com/repo --stdlayout --authors-file=~/authors.txt my-git-repo
    ```

    This process may take time depending on the size of your repository and the number of revisions.

    # If your repo doesn't follow standard svn layout

    If your repo doesn't have the normal "trunk", "branch", "tag" folder structure, you will have to clone them a different way.
    Start by finding the folder structure:

    ```bash
    svn ls <SVN_REPO_URL>
    ```

    You should get a list of folders/files. If no "trunk" is given, then "/" is your trunk.

    ## Run git svn clone with custom paths

    ```bash
    git svn clone <SVN_REPO_URL> --trunk=<TRUNK_PATH> --branches=<BRANCHES_PATH> --tags=<TAGS_PATH> <LOCAL_DIR>
    ```

    If you have no branches or tags folders then ignore those.

    Example (assuming "project" is a folder):

    ```bash
    git svn clone http://svn.example.com/repo --trunk=project my-git-repo
    ```

    # Navigate to the New Git Repository

    Once the cloning is complete, move into the new Git repository:

    ```bash
    cd my-git-repo
    ```

    # Clean Up Branches and Tags

    The git-svn tool imports SVN branches and tags as remote branches (e.g., remotes/origin/trunk, remotes/origin/tags/tag1).
    You’ll need to convert these into proper Git branches and tags.

    ### Rename trunk to master (or main): If your SVN trunk was imported as a branch, rename it to align with Git conventions:

    ```bash
    git branch -m trunk master
    ```

    ### Convert SVN Tags to Git Tags

    SVN tags are imported as branches under remotes/origin/tags/.
    Convert them to proper Git tags with this script:

    ```bash
    git for-each-ref --format='%(refname)' refs/remotes/origin/tags | while read ref; do
    tagname=$(echo $ref | cut -d'/' -f5)
    git tag "$tagname" "$ref"
    git branch -r -d "origin/tags/$tagname"
    done
    ```

    This creates Git tags and removes the redundant tag branches.

    ### Convert SVN Branches to Git Branches

    Move other SVN branches (e.g., remotes/origin/branch1) to local Git branches:

    ```bash
    git branch branch1 refs/remotes/origin/branch1
    git branch -r -d origin/branch1
    ```

    Repeat for each branch you want to keep.

    # Add Bitbucket as a Remote

    ### Link your local Git repository to the empty Bitbucket repository

    ```bash
    git remote add origin <BITBUCKET_REPO_URL>
    ```

    - <BITBUCKET_REPO_URL>: The URL of your Bitbucket repository (e.g., git@bitbucket.org:username/repo.git).
    - You can find this on the Bitbucket repository page under "Clone."

    # Push the Repository to Bitbucket

    Push all branches and tags to Bitbucket:

    ```bash
    git push origin --all
    git push origin --tags
    ```

    - --all: Pushes all branches.
    - --tags: Pushes all tags.

    # Verify the Migration

    Visit your Bitbucket repository in a browser to confirm that the commits, branches, and tags have been successfully migrated.
    Use git log locally to double-check the history:

    ```bash
    git log
    ```

    # Additional Tips

    - Large Repositories: For very large SVN repositories, the git svn clone process can be slow.
    You can speed it up by specifying a revision range with -r (e.g., -r 1000:HEAD to start from revision 1000).

    - Authentication: If your SVN repository requires credentials, add them to the git svn clone command
    (e.g., --username=youruser --password=yourpass), or let it prompt you.

    - Testing: Before pushing to Bitbucket, test the local Git repository to ensure everything looks correct.

    - Alternative Tools: If git-svn doesn’t meet your needs, consider tools like svn2git or SubGit, which offer additional features but may require more setup.