Subversion Command Line Primer

11:14 pm Linux

Below is an aggregate of my notes on how to use command line Subversion. The syntax may not be 100% correct (may have changed in newer versions) so please adapt accordingly.

Note: For more details, refer to the free book, Version Control with Subversion, written by some of the Subversion developers.

Though I’m using Linux syntax below, the Subversion commands should also work on Windows and macOS.

# Show version installed
svn --version

# ------------ Local Admin ------------

# Create a repository
sudo mkdir /var/repos
sudo svnadmin create /var/repos

# Export a repository
svnadmin dump /var/repos > backup.svn

# Import a repository
svnadmin load /var/repos < backup.svn

# List all projects in the local repository.
svn list file:///var/repos

# ------------ Basic Remote Client ------------

# List all projects in the remote repository by svn+ssh or HTTP URI.
svn list svn+ssh://myuser@mydomain.com/var/repos
svn --username <myuser> --password <mypassword> list http://mydomain.com/var/repos

# Import a project into the repository
svn import ./myproject svn+ssh://myuser@mydomain.com/var/repos/myproject -m "Initial Import"

# Check out a local, working copy of a project from the repository
svn co svn+ssh://myuser@mydomain.com/var/repos/myproject ./myproject

# View the working copy's info (no need to input the URI once inside the project)
cd ./myproject
svn info

# Update the project to the latest version
svn update

# Add a new file
svn add newfile.cpp

# Remove a file
svn rm oldfile.cpp

# Move and/or rename a file
svn mv oldfile.cpp subdir/newoldfile.cpp

# Set file to be binary type
svn propset svn:mime-type 'application/octet-stream' myfile.bin

# Have Subversion ignore certain subdirectories or files
svn propedit svn:ignore .

# List the modified files/directories (aka status) made to working copy
svn status
svn st

# Show differences between local files and current revision (usually HEAD)
svn diff

# Commit (aka checkin) all local working changes to the repository
svn commit -m "first commit"
svn ci -m "first commit"

# Show checkin logs (revision number, user, time, checkin comment)
svn log

# List files modified by a particular revision
svn log -v -r <revision_number>

# Show line-by-line differences in a particular revision's changeset
svn diff -c <revision_number>

# ------------ Selective Commit ------------

# Create changelist for selective commit
svn changelist <changelist-name> file1 file2 file3

# Add or remove files from the selective changelist
svn changelist <changelist-name> --add file4
svn changelist <changelist-name> --remove file2

# Show differences in selective changelist
svn diff --changelist <changelist-name>

# Checkin only files listed in selective changelist
svn ci -m "comment" --changelist <changelist-name>

# ------------ Undelete a File ------------

# Find version when deletion took place
svn log verbose

# Undelete by copying back from revision (one prior to deletion revision) to current
svn copy --revision 835 http://mydomain.com/myproject/myfile.cpp .

# If get "Path not found", then add a revision suffix to the URI
svn copy ‐‐revision 835 http://mydomain.com/myproject/myfile.cpp@835 .

# ------------ Switch to Previous Revision ------------

# Revert to previous revision
svn up -r [revision_number]

# Show files that have changed
svn st --show-updates

# diff against latest revision (diff by itself won't show any differences)
svn diff -r HEAD
   
# ------------ Branching and Merging ------------

# Find revision when branched from trunk
svn log -v --stop-on-copy

# Revert back to an earlier revision
svn merge -r 10340:10335 <file or dir>

# Merge just one file
svn merge -r10343:10739 https://mydomain.com/myproject/myfile.cpp ./myfile.cpp

# Merge from trunk to branch
svn merge --dry-run -r10810:HEAD https://mydomain.com/myproject/trunk/ .
svn merge -r10810:HEAD --accept mine-conflict https://mydomain.com/myproject/trunk/ .

# Merge from branch to trunk (automatically accept theirs-full if conflict)
svn merge --reintegrate --accept theirs-full https://mydomain.com/myproject/branches/mybranch .

# Update working copy to use a different branch
svn switch http://mydomain/myproject/branches/mybranch .
Leave a Comment

Your comment

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.