Skip to content

Subversion Command Line Primer

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_old > backup.svn

# Remove a folder/file from dump file (permanently delete from repos)
svndumpfilter exclude myproject1 < backup.svn > backup_filtered.svn

# Import a repository (needs to be new blank repos)
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

# 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 check in) all local working changes to the repository
svn commit -m "first commit"
svn ci -m "first commit"

# Show check in logs (revision number, user, time, check in 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>

# ------------ Ignore Files and Subdirs ------------

# Have Subversion ignore file(s) and subdir in a directory
cd dir_name
svn propset svn:ignore file.cpp .
svn propset svn:ignore *.class .
svn propset svn:ignore subdir_name .

# Edit svn:ignore settings
# Have to set environment variables SVN_EDITOR to your editor
svn propedit svn:ignore .

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

# Show all properties set under a directory
svn proplist .
svn proplist dir_name

# Recursively show all properties set under a directory
svn proplist -v -R .
svn proplist -v -R dir_name

# Do a status that includes even svn:ignore files and dirs
svn status --no-ignore

# ------------ 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>

# Check in 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 a file to HEAD revision (discard local changes)
svn revert file.cpp

# 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 ------------

# Branch using copy command
svn copy svn+ssh://mydomain.com/myproject/trunk svn+ssh://mydomain.com/myproject/branches/mybranch

# 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 .

Some info above taken from:

Leave a Reply

Your email address will not be published. Required fields are marked *