Skip to content

svn Git Command Guide

The git svn command provides bidirectional operation between Subversion (SVN) and Git repositories, allowing teams to migrate from SVN to Git or maintain compatibility with existing SVN infrastructure. It enables Git users to interact with SVN repositories while preserving Git’s advanced features locally.

Terminal window
git svn <command> [<options>] [<arguments>]
CommandDescription
cloneClone SVN repository to Git
initInitialize Git repository for SVN tracking
fetchFetch changes from SVN
pullFetch and rebase from SVN
rebaseRebase local changes onto SVN HEAD
dcommitCommit local Git changes to SVN
logShow SVN log messages
blameShow SVN blame information
find-revFind Git commit for SVN revision
set-treeSet tree for specific SVN revision
create-ignoreCreate .gitignore from svn:ignore
show-ignoreShow SVN ignore patterns
mkdirsRecreate empty SVN directories
commit-diffCommit diff between revisions
OptionDescription
-r <revision>Specify SVN revision
--revision=<rev>SVN revision (same as -r)
-s, --stdlayoutAssume standard trunk/branches/tags layout
-T <trunk>Trunk directory
-t <tags>Tags directory
-b <branches>Branches directory
--prefix=<prefix>Prefix for SVN tracking branches
-A <authors-file>Authors file for mapping
--authors-prog=<cmd>Program to generate author mapping
--no-auth-cacheDon’t cache SVN credentials
ParameterDescription
<URL>SVN repository URL
<path>Local path or file
<revision>SVN revision number
SVN Repository Structure:
├── trunk/ -> Git: main/master branch
├── branches/ -> Git: remote tracking branches
│ ├── feature-x/ -> Git: remotes/git-svn/feature-x
│ └── bugfix-y/ -> Git: remotes/git-svn/bugfix-y
└── tags/ -> Git: tags (annotated)
Git-SVN Tracking:
├── git-svn-id: <URL>@<rev> <UUID>
├── Remote branches: git-svn, git-svn-<branch>
└── Linear history: SVN revisions as Git commits
Git-SVN Bidirectional Flow:
├── SVN -> Git: git svn fetch/rebase
├── Git -> SVN: git svn dcommit
├── Local Git: Full Git features (branches, merges)
└── SVN Sync: Linear commit history to SVN
Author Mapping Strategies:
├── Authors file: username = Full Name <email@domain.com>
├── Authors program: Dynamic author resolution
├── Default: username <username@UUID>
└── Manual override: --authors-prog option
Terminal window
# Clone entire SVN repository
git svn clone <svn-url> [local-dir]
# Clone with standard layout (trunk/branches/tags)
git svn clone -s <svn-url> [local-dir]
# Clone specific branch
git svn clone -b <branch> <svn-url> [local-dir]
# Clone with author mapping
git svn clone --authors-file=authors.txt <svn-url>
Terminal window
# Initialize Git repo for SVN tracking
git svn init <svn-url>
# Initialize with custom layout
git svn init -T trunk -b branches -t tags <svn-url>
# Add author mapping
git svn init --authors-file=authors.txt <svn-url>
Terminal window
# Fetch latest changes from SVN
git svn fetch
# Fetch specific revision range
git svn fetch -r 1000:HEAD
# Fetch and rebase (equivalent to pull)
git svn rebase
# Fetch with verbose output
git svn fetch --verbose
Terminal window
# Commit local changes to SVN
git svn dcommit
# Commit with specific message
git svn dcommit -m "Commit message"
# Dry run commit
git svn dcommit --dry-run
# Commit specific commits
git svn dcommit HEAD~3..HEAD
Terminal window
# Create new SVN branch from Git
git svn branch <branch-name>
# Switch to SVN branch
git checkout remotes/git-svn/<branch-name>
# Merge Git branches before SVN commit
git merge feature-branch
git svn dcommit
Terminal window
# Create SVN tag from Git
git svn tag <tag-name>
# Create tag from specific commit
git svn tag <tag-name> -r <revision>
# List SVN tags
git branch -r | grep tags/
Terminal window
# Create authors file
cat > authors.txt << 'EOF'
jdoe = John Doe <john.doe@company.com>
asmith = Alice Smith <alice.smith@company.com>
bwilson = Bob Wilson <bob.wilson@company.com>
EOF
# Use authors file
git svn clone --authors-file=authors.txt <svn-url>
# Use authors program
git svn clone --authors-prog=./author-lookup.sh <svn-url>
Terminal window
# Create .gitignore from svn:ignore
git svn create-ignore
# Show SVN ignore patterns
git svn show-ignore
# Update ignore patterns
git svn create-ignore --revision=HEAD
Terminal window
# Configure global SVN settings
git config --global svn.authorsfile ~/svn-authors.txt
git config --global svn.noMetadata false
git config --global svn.useSvkProps false
git config --global svn.useSvndumpProps false
# Configure remote tracking
git config svn-remote.svn.url <svn-url>
git config svn-remote.svn.fetch :refs/remotes/git-svn
git config svn-remote.svn.branches branches/*:refs/remotes/git-svn/*
Terminal window
# Always fetch before committing
git svn fetch && git svn rebase
# Use rebase instead of merge
git svn rebase # Instead of git pull
# Keep linear history for SVN
# Avoid Git merges before dcommit
# Regular repository maintenance
git gc --aggressive
git svn gc
Terminal window
# Safe migration approach
# 1. Clone SVN repository
git svn clone -s <svn-url> project-git
# 2. Verify all history
git log --oneline | tail -20
# 3. Test build and functionality
# ... run tests ...
# 4. Switch team to Git
# ... team training and migration ...
# 5. Stop SVN commits (read-only)
# ... update SVN permissions ...
#!/bin/bash
# Complete SVN to Git migration
migrate_svn_to_git() {
local svn_url="$1"
local git_repo="$2"
local authors_file="${3:-authors.txt}"
echo "Migrating SVN repository to Git..."
echo "SVN URL: $svn_url"
echo "Git Repo: $git_repo"
# Create authors mapping
if [ ! -f "$authors_file" ]; then
echo "Creating authors file..."
# Extract authors from SVN
svn log "$svn_url" --xml | grep -E '<author>' | \
sed 's/<author>//g' | sed 's/<\/author>//g' | \
sort | uniq > svn-authors.tmp
# Create mapping file
while read -r author; do
echo "$author = $author <$author@company.com>"
done < svn-authors.tmp > "$authors_file"
rm svn-authors.tmp
echo "Edit $authors_file to add proper names and emails"
return 1
fi
# Clone SVN repository
echo "Cloning SVN repository..."
git svn clone --authors-file="$authors_file" \
--stdlayout \
--no-metadata \
"$svn_url" \
"$git_repo"
cd "$git_repo" || return 1
# Convert SVN tags to Git tags
echo "Converting SVN tags to Git tags..."
git for-each-ref refs/remotes/git-svn/tags | while read -r ref; do
tag_name=$(basename "$ref")
git tag "$tag_name" "$ref"
done
# Convert branches
echo "Converting SVN branches..."
git for-each-ref refs/remotes/git-svn | \
grep -v tags | while read -r ref; do
branch_name=$(basename "$ref")
if [ "$branch_name" != "trunk" ]; then
git branch "$branch_name" "$ref"
fi
done
# Clean up remote refs
git branch -r | grep git-svn | xargs -n1 git branch -r -d 2>/dev/null || true
# Set up Git remote (optional)
echo "Setting up Git remote repository..."
# git remote add origin <git-url>
# git push -u origin main
echo "Migration complete!"
echo "Repository: $git_repo"
echo "Authors file: $authors_file"
}
migrate_svn_to_git "https://svn.company.com/repo" "project-git"
Terminal window
# Maintain bidirectional SVN-Git workflow
bidirectional_workflow() {
echo "=== Bidirectional SVN-Git Workflow ==="
# Fetch latest SVN changes
git svn fetch
# Rebase local changes on SVN HEAD
git svn rebase
# Work with Git features locally
git checkout -b feature-branch
# ... make changes ...
git commit -m "Implement feature"
# Merge back to SVN tracking branch
git checkout git-svn
git merge feature-branch
# Commit to SVN
git svn dcommit
# Clean up
git branch -d feature-branch
}
bidirectional_workflow
Terminal window
# Git-SVN in CI/CD pipeline
ci_svn_integration() {
echo "=== CI/CD with Git-SVN ==="
# Fetch latest changes
git svn rebase
# Run tests
if ! run_tests; then
echo "Tests failed"
exit 1
fi
# Build application
if ! run_build; then
echo "Build failed"
exit 1
fi
# Commit build artifacts to SVN
git add build-artifacts/
git commit -m "Build $(date +%Y%m%d-%H%M%S) [ci skip]"
# Push to SVN
git svn dcommit
echo "CI/CD pipeline completed"
}
ci_svn_integration
Terminal window
# Clear SVN auth cache
rm -rf ~/.subversion/auth
# Force re-authentication
git svn dcommit --username=newuser
# Use different credentials
git svn clone --username=user --password=pass <url>
# Configure credential storage
git config svn.authorsfile ~/svn-authors.txt
Terminal window
# Find Git commit for SVN revision
git svn find-rev r1234
# Find SVN revision for Git commit
git log --grep="git-svn-id.*@1234"
# Rebuild revision mapping
git svn reset -r <revision>
git svn fetch
Terminal window
# Handle conflicting branch names
git branch -m git-svn svn-trunk
git svn reset --parent
# Fix tag conflicts
git tag -d conflicting-tag
git svn tag conflicting-tag
Terminal window
# Handle encoding problems
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
# Convert repository encoding
git svn clone --encoding=utf-8 <svn-url>
# Fix existing repository
git filter-branch --tree-filter 'recode latin1..utf8 *' HEAD
Terminal window
# Optimize large repository handling
git config svn.brokenSymlinkWorkaround true
git config core.deltaBaseCacheLimit 2g
# Use shallow clone for testing
git svn clone -r HEAD:HEAD-100 <svn-url>
# Clean up repository
git gc --aggressive
git svn gc
Terminal window
# Handle SVN rebase conflicts
git status
# Resolve conflicts manually
# Edit conflicted files
git add resolved-file.txt
# Continue rebase
git rebase --continue
# Abort if needed
git svn rebase --abort
#!/bin/bash
# Enterprise SVN to Git migration
enterprise_migration() {
local svn_root="$1"
local git_org="$2"
local projects=("project-a" "project-b" "project-c")
echo "=== Enterprise SVN Migration ==="
echo "SVN Root: $svn_root"
echo "Git Org: $git_org"
# Create authors file
create_enterprise_authors() {
echo "Creating enterprise authors file..."
# Query LDAP/Active Directory for users
# This is a simplified example
cat > enterprise-authors.txt << 'EOF'
jdoe = John Doe <john.doe@company.com>
asmith = Alice Smith <alice.smith@company.com>
bwilson = Bob Wilson <bob.wilson@company.com>
EOF
echo "Enterprise authors file created"
}
# Migrate individual projects
migrate_project() {
local project="$1"
local svn_url="$svn_root/$project"
local git_repo="$project-git"
echo "Migrating project: $project"
# Clone with enterprise settings
git svn clone \
--authors-file=enterprise-authors.txt \
--stdlayout \
--no-metadata \
--preserve-empty-dirs \
"$svn_url" \
"$git_repo"
cd "$git_repo" || return 1
# Convert branches and tags
git for-each-ref refs/remotes/git-svn/tags | \
sed 's|refs/remotes/git-svn/tags/||' | \
xargs -I {} git tag {} refs/remotes/git-svn/tags/{}
# Setup Git remotes
git remote add origin "https://github.com/$git_org/$project.git"
# Initial push
git push -u origin main
git push origin --tags
cd ..
echo "Project $project migrated"
}
# Main migration process
create_enterprise_authors
for project in "${projects[@]}"; do
migrate_project "$project"
done
# Generate migration report
cat > migration-report.txt << EOF
Enterprise Migration Report
Migration Date: $(date)
SVN Root: $svn_root
Git Organization: $git_org
Migrated Projects:
$(printf -- '- %s\n' "${projects[@]}")
Authors File: enterprise-authors.txt
Migration Script: $0
Next Steps:
1. Update CI/CD pipelines
2. Update documentation
3. Train development teams
4. Archive SVN repositories (read-only)
5. Monitor for issues
EOF
echo "Enterprise migration completed"
echo "See migration-report.txt for details"
}
enterprise_migration "https://svn.company.com" "company-org"
Terminal window
# Gradual SVN to Git migration
gradual_migration() {
echo "=== Gradual SVN-Git Migration ==="
# Phase 1: Read-only Git mirror
setup_git_mirror() {
local svn_url="$1"
local mirror_dir="${2:-git-mirror}"
echo "Setting up Git mirror..."
git svn clone --mirror "$svn_url" "$mirror_dir"
cd "$mirror_dir"
# Setup automatic sync
cat > sync-svn.sh << 'EOF'
#!/bin/bash
cd "$(dirname "$0")"
git svn fetch
git update-server-info
EOF
chmod +x sync-svn.sh
# Setup cron for regular sync
echo "*/15 * * * * $(pwd)/sync-svn.sh" | crontab -
echo "Git mirror setup complete"
}
# Phase 2: Team migration
migrate_team() {
local team_members="$1"
echo "Migrating team to Git..."
for member in $team_members; do
echo "Setting up Git for $member..."
# Clone team repository
git clone git-mirror "$member-repo"
# Setup Git configuration
cd "$member-repo"
git config user.name "$member"
git config user.email "$member@company.com"
# Create feature branch
git checkout -b "$member-feature"
cd ..
done
echo "Team migration setup complete"
}
# Phase 3: Final cutover
final_cutover() {
echo "Performing final cutover..."
# Last SVN sync
cd git-mirror
git svn fetch
# Make SVN read-only
echo "Make SVN repository read-only now"
# Final Git push
git push origin --mirror
# Update all team repos
for repo in *-repo; do
cd "$repo"
git pull origin main
cd ..
done
echo "Final cutover complete"
}
# Interactive migration
echo "Gradual Migration Options:"
echo "1. Setup Git mirror"
echo "2. Migrate team"
echo "3. Final cutover"
read -p "Select phase (1-3): " phase
case "$phase" in
1)
read -p "SVN URL: " svn_url
setup_git_mirror "$svn_url"
;;
2)
read -p "Team members (space-separated): " team
migrate_team "$team"
;;
3)
final_cutover
;;
*) echo "Invalid option" ;;
esac
}
gradual_migration
Terminal window
# Maintain SVN-Git bridge for legacy systems
svn_bridge_maintenance() {
echo "=== SVN-Git Bridge Maintenance ==="
# Sync Git to SVN
sync_git_to_svn() {
echo "Syncing Git changes to SVN..."
# Fetch latest Git changes
git fetch origin
# Rebase on latest
git rebase origin/main
# Commit to SVN
git svn dcommit
echo "Git->SVN sync complete"
}
# Sync SVN to Git
sync_svn_to_git() {
echo "Syncing SVN changes to Git..."
# Fetch from SVN
git svn fetch
# Rebase local changes
git svn rebase
# Push to Git
git push origin main
echo "SVN->Git sync complete"
}
# Bidirectional sync
bidirectional_sync() {
echo "Performing bidirectional sync..."
# Pull from both
git fetch origin
git svn fetch
# Check for conflicts
if git merge-base --is-ancestor origin/main git-svn; then
# Git is ahead
sync_git_to_svn
elif git merge-base --is-ancestor git-svn origin/main; then
# SVN is ahead
sync_svn_to_git
else
# Diverged - manual intervention needed
echo "Repositories have diverged - manual merge required"
exit 1
fi
}
# Maintenance tasks
maintenance_tasks() {
echo "Running maintenance tasks..."
# Clean up old refs
git for-each-ref --format="%(refname)" refs/remotes/git-svn | \
xargs -n1 git update-ref -d 2>/dev/null || true
# Repack repository
git repack -a -d
# Clean SVN metadata
git svn gc
echo "Maintenance complete"
}
# Interactive bridge maintenance
echo "SVN-Git Bridge Maintenance:"
echo "1. Sync Git to SVN"
echo "2. Sync SVN to Git"
echo "3. Bidirectional sync"
echo "4. Maintenance tasks"
read -p "Select operation (1-4): " operation
case "$operation" in
1) sync_git_to_svn ;;
2) sync_svn_to_git ;;
3) bidirectional_sync ;;
4) maintenance_tasks ;;
*) echo "Invalid option" ;;
esac
}
svn_bridge_maintenance
Terminal window
# Integrate with legacy SVN-based systems
legacy_integration() {
echo "=== Legacy System Integration ==="
# Setup SVN webhook equivalent
setup_svn_hooks() {
echo "Setting up SVN-style hooks..."
# Post-commit hook equivalent
cat > .git/hooks/post-commit << 'EOF'
#!/bin/bash
# Equivalent to SVN post-commit hook
# Notify legacy systems
curl -X POST "http://legacy-system/api/git-commit" \
-H "Content-Type: application/json" \
-d "{\"commit\":\"$(git rev-parse HEAD)\", \"message\":\"$(git log -1 --pretty=%B)\"}"
# Update documentation
./update-docs.sh
EOF
chmod +x .git/hooks/post-commit
# Pre-commit checks
cat > .git/hooks/pre-commit << 'EOF'
#!/bin/bash
# Equivalent to SVN pre-commit checks
# Run legacy validation
if ! ./legacy-validation.sh; then
echo "Legacy validation failed"
exit 1
fi
# Check code standards
if ! ./check-standards.sh; then
echo "Code standards check failed"
exit 1
fi
EOF
chmod +x .git/hooks/pre-commit
}
# SVN-style access control
setup_access_control() {
echo "Setting up access control..."
# Create access control script
cat > git-access-control.sh << 'EOF'
#!/bin/bash
# SVN-style access control
USER="$1"
PATH="$2"
ACTION="$3"
# Read access - generally allowed
if [ "$ACTION" = "read" ]; then
exit 0
fi
# Write access - check permissions
case "$USER" in
admin|manager)
# Full access
exit 0
;;
developer)
# Development branches only
if [[ "$PATH" == refs/heads/dev* ]]; then
exit 0
fi
;;
*)
# No write access
echo "Access denied for user $USER to $PATH"
exit 1
;;
esac
EOF
chmod +x git-access-control.sh
}
# Automated SVN reporting
setup_reporting() {
echo "Setting up automated reporting..."
cat > generate-svn-report.sh << 'EOF'
#!/bin/bash
# Generate SVN-style reports
echo "=== SVN-Style Repository Report ==="
echo "Generated: $(date)"
echo
echo "Recent Commits:"
git log --oneline -10 --no-merges
echo
echo "Active Branches:"
git branch -r | grep -v HEAD
echo
echo "Repository Statistics:"
echo "Commits: $(git rev-list --count HEAD)"
echo "Contributors: $(git shortlog -sn | wc -l)"
echo "Branches: $(git branch -r | wc -l)"
echo "Tags: $(git tag | wc -l)"
EOF
chmod +x generate-svn-report.sh
# Schedule daily reports
(crontab -l ; echo "0 9 * * * $(pwd)/generate-svn-report.sh | mail -s 'Daily Git Report' admin@company.com") | crontab -
}
# Interactive setup
echo "Legacy Integration Options:"
echo "1. Setup SVN-style hooks"
echo "2. Setup access control"
echo "3. Setup automated reporting"
read -p "Select option (1-3): " option
case "$option" in
1) setup_svn_hooks ;;
2) setup_access_control ;;
3) setup_reporting ;;
*) echo "Invalid option" ;;
esac
}
legacy_integration

What’s the difference between git svn and regular Git?

Section titled “What’s the difference between git svn and regular Git?”

git svn bridges Git and SVN repositories, allowing bidirectional operation. Regular Git is native Git without SVN compatibility layer.

Use git svn clone with —stdlayout and —authors-file options. Convert branches/tags, then push to Git remote.

Yes, use full Git features locally (branches, merges, etc.), but dcommit requires linear history for SVN compatibility.

Create authors file mapping SVN usernames to full names/emails: username = Full Name email@domain.com

What’s the difference between git svn rebase and git pull?

Section titled “What’s the difference between git svn rebase and git pull?”

git svn rebase fetches from SVN and rebases local changes. git pull is for Git remotes; use rebase for SVN.

Yes, git svn clone —stdlayout tracks trunk/branches/tags. Branches appear as Git remote branches.

Use git svn dcommit to commit local Git commits to SVN. Requires linear history.

Metadata added by git svn showing SVN URL, revision, and repository UUID for tracking.

Can I use git svn with existing Git repository?

Section titled “Can I use git svn with existing Git repository?”

Yes, use git svn init to add SVN tracking to existing Git repo, then git svn fetch.

How do I find the Git commit for an SVN revision?

Section titled “How do I find the Git commit for an SVN revision?”

Use git svn find-rev to locate the corresponding Git commit.

What’s the performance impact of git svn?

Section titled “What’s the performance impact of git svn?”

git svn can be slower than native Git due to SVN protocol overhead. Use for migration/compatibility, not primary workflow.

Can git svn handle large SVN repositories?

Section titled “Can git svn handle large SVN repositories?”

Yes, but may require incremental fetching and patience. Use —revision to limit initial clone size.

How do I clean up after git svn migration?

Section titled “How do I clean up after git svn migration?”

Remove .git/svn directory, clean reflog, consider filter-branch to remove git-svn-id metadata.

Can multiple people use git svn on same repository?

Section titled “Can multiple people use git svn on same repository?”

Yes, but coordinate dcommits to avoid conflicts. Each user should rebase before committing.

  1. SVN Migration: Migrate repositories from Subversion to Git with full history preservation
  2. Bidirectional Workflow: Maintain compatibility with existing SVN infrastructure while using Git locally
  3. Gradual Transition: Enable teams to adopt Git incrementally while maintaining SVN access
  4. Legacy Integration: Connect modern Git workflows with legacy SVN-based systems
  5. Bridge Operations: Support hybrid development environments with mixed version control systems
  6. Historical Preservation: Maintain complete project history during version control transitions
  7. Enterprise Compatibility: Meet organizational requirements for SVN usage while enabling Git benefits
  8. Training and Adoption: Allow teams to learn Git while maintaining SVN safety nets