Você está na página 1de 7

Subversion Commands and Scripts 18/07/2017, 19*46

Home (/) > Tutorials (/TUTORIALS/) > Subversion Commands and Scripts (/TUTORIALS/Subversion.html)

Subversion Commands
and Scripts
Subversion (SVN) command summary cheat sheet, use, best
practices, tips and scripts. This tutorial covers version control with
Subversion using the command line interface, GUI clients and scripts which interface Subversion
with GUI diff tools.

(http://www.yolinux.com/)

Tutorial Contents: rev 401 rev 402 rev 403


# Subversion Introduction
# Subversion Commands
# Subversion content properties
# Subversion and Graphical diffs
# Subversion GUI interface
# Subversion Security Tips
# Subversion utility commands and scripts
# Subversion Best Practices
# Tips
# Links
# Books

search
| Home Page (/) | Linux Tutorials (/TUTORIALS/) | Terms (/YoLinux-Terms.html) | Privacy Policy (/privacy.html) |
Advertising (/YoLinux-Advertising.html) | Contact (/YoLinuxEmailForm.html) |
Search

Related YoLinux Tutorials:


Subversion Introduction:
°Subversion Server and Trac Server
Subversion is a software source code "Change Management" (CM) system for collaborative
Installation and Configuration
development. It maintains a history of file and directory versions. The files and directories are
(LinuxSubversionAndTracServer.html)
checked out of the repository and into your local project work area. This called your "working
directory". Changes are made to files in your "working directory". After changes are made to
°Subversion Repository Transfer
the create the next working version, the files are checked into the Subversion CM repository.
(SubversionRepositoryDataTransfer.html)

°RabbitVCS client (SVN-Client-


RabbitVCS.html)
Subversion Commands:
Subversion command summary cheat sheet:
°Git Server Configuration (GIT-Server-
Configuration.html) Command Description
°Jenkins Automated Builds andsvn --help List Subversion commands
Subversion (Jenkins.html) svn help command Help on given "command"
Also: ? or h
°Cabie Automated Builds and Subversion
(CabieBuildSystem.html) svn add filename Add a file or directory to Subversion
svn add directory CM control.
°Software development tools
Must also perform: svn ci
(LinuxTutorialSoftwareDevelopment.html)
filename (or svn commit) to
°Clearcase Commands upload the file or directory. File will not
(ClearcaseCommands.html) be available in the repository until a
"commit" is performed. If adding a
°Clearcase Client Install
directory, the directory and all of its
(LinuxClearcaseClient.html)
contents recursively are added. i.e.:

http://www.yolinux.com/TUTORIALS/Subversion.html Page 1 of 21
Subversion Commands and Scripts 18/07/2017, 19*46

°Clearcase Server Install svn ci directory


(LinuxClearcaseServerInstallation.html) svn commit directory
svn commit .
°Subversion vs Clearcase
(SubversionVsClearcase.html) svn blame filename Show file contents with revisions
svn blame -r RevisionNumber filename annotated with author information.
°CVS Intro (LinuxTutorialCVSintro.html)
Also: praise, annotate, ann
svn cat filename
°RCS Intro (LinuxTutorialRCSintro.html) List contents of file under Subversion
control.
°C++ Info, links (LinuxTutorialC++.html)
svn checkout http://node- Checkout every file from the path and
°Java on Linux (LinuxTutorialJava.html)
name/repos/svn/trunk/parentPath/path subdirectories specified below.
This creates:
°YoLinux Tutorials Index (/TUTORIALS/) Creates "working" copy of files and
path/file1 directories.
path/file2 Checkout a repository.
... Use option "-r" to specify a specific
svn checkout http://node- revision other than the latest.
name/repos/svn/trunk/parentPath .
The URL "svn://" communicates with
This creates:
Free Information Technology an SVN server (port 3690)
path/file1
Magazines and Document
path/file2 The URL "http://" comunicates with the
Downloads
... Apache server and module
Note the difference a "." makes. mod_dav_svn (port 80) [more
common server]
svn checkout
file:///repos/svn/trunk/path/
svn co -r 497 http://node-
name/repos/svn/trunk/path file-name
(http://yolinux.tradepub.com/)svn co --username user1 http://node-
name/repos/svn/trunk/path
Free Information
Also: svn co https://..., svn://...,
Technology Software and
and svn+ssh://
Development Magazine
MS/Windows: svn co
Subscriptions and file:///c:/repository/project/trunk
Document Downloads
(http://yolinux.tradepub.co svn cleanup Cleanup subversion files resulting from
m/?pt=cat&page=Infosoft) escaped processes and crashed.
svn commit filename Check-in (commit) local "working" file,
svn commit --message "Message goes files or directory and contents
here." filename (recursively) into Subversion
svn commit -m "Message goes here." repository. Atomic, i.e. all committed or
filename none, no incomplete check-in.
svn ci filename1 filename2 filename3
svn ci .
svn copy source destination_clone Copy file or directory tree. One can
Also: svn cp ... copy from one local working copy to
another or to repository server URL's.
The sources and destinations can be
working copies or URLs.
svn copy Tag a release. Takes a snapshot of the
http://host/repos/project/trunk repository and assigns a name. This
http://host/repos/project/tags/TagName- can be performed at any directory
1.4.5 -m "Tag Release 1.4.5" branch.
svn copy . Tag a release. Takes a snapshot of
http://host/repos/project/tags/TagName- your local working copy and assigns a
1.4.5 -m "Tag Release 1.4.5" name. This can be performed at any
directory branch.

http://www.yolinux.com/TUTORIALS/Subversion.html Page 2 of 21
Subversion Commands and Scripts 18/07/2017, 19*46

svn delete filename Delete file from repository. The UNIX


svn delete directory command rm file-name. Must
Also: del, remove or rm perform a "commit" to update the
svn rm repository and local working directory
http://host/repos/project/trunk/file- with the changes. i.e.:
or-directory svn commit .
svn diff filename Show file diffs between SVN repository
svn di filename and your file changes using GNU file
diff format. Use GUI diff tools as
shown below.
svn diff -r rev1:rev2 filename Show file diffs between specified
versions.
Example: svn diff -r 456:459
subfn.cpp
Using GUI diff tool: svn diff -r
457:459 --diff-cmd kdiff3
file-name
svn diff filename > patch-file Generate patch file used by the patch
command (http://man.yolinux.com/cgi-
bin/man2html?cgi_command=patch).
svn export directory Export directory tree to your file
system but it will not be a "working
directory" under SVN control.
svn export -r Rev-Number http://node- Export directory tree of specified
name/path version and create local directory tree
and files not under SVN control.
svn import local-directory Add directory contents (files in it
http://host/repos/svn/trunk/directory recursively) to path in repository
Typical Import: specified.
svn mkdir
http://host/repos/svn/trunk/ProjectX
svn import -m"Initial import" ProjectX
http://host/repos/svn/trunk/ProjectX

svn info filename Display information about file or


directory. (Date modified, author,
revision, path in repository.)
Can not specify a URL.
svn list directory List file or directory of files in
svn list file-name repository. Used to browse repository
before checkout. If current directory is
given (svn list ./), then
Subversion will list the repository URL
of the current directory.
svn list -r RevisionNumber directory List directory of files in repository in
specified revision.
svn lock filename -m "comment as to why Lock file to grant exclusive access to
its locked or by whom" one and forbid all others. A commit will
unlock the file (unless the "--no-
unlock" option is used). A lock can be
(Comment is not required but is often
removed with the commands: svn
useful)
unlock filename, svnlook and
the svnadmin comands (i.e. List:
svnadmin lslocks and remove:

http://www.yolinux.com/TUTORIALS/Subversion.html Page 3 of 21
Subversion Commands and Scripts 18/07/2017, 19*46

svnadmin rmlocks filename).


svn log filename Show the Subversion log messages
svn log . for a set of revision(s) and/or file(s)
svn log http://URL/path/file and/or all directory contents in
svn log -v . repository.
svn log -r RevisionNumber List verbose. Includes list of all files in
http://URL/path/file change
Shows the file changes associated
with revision number.
svn merge http://url/path/branch1 Merge directory changes into your
http://url/path/branch2 working-local- current working directory or merge a
dir file in Subversion into the file in your
svn merge file1@revJ file2@revK working directory. If target is not
svn merge -r 414:411 http://url/path specified, the identical basename or
working-dir current directory is assumed. Used to
svn merge -r 413:HEAD file-name incorporate changes checked in which
are not accounted for in your file or to
merge branches.
Example using GUI merge tool:
svn diff -r 459:454 --diff-
cmd kdiff3 --extensions '-m'
file-name
Next, tell subversion that the conflicts
have been resolved:
svn resolve file-name
Finally, check-in file: svn ci file-
name
or abort changes: svn revert
file-name

svn merge --dry-run -r 414:413 Test merge. No changes are made to


http://url/path your local working copy but shows
Subversion feedback as if merge was
performed.
svn merge -r 414:413 http://url/path Undo changes committed in revision
svn merge -r 414:413 . 414.
svn mkdir directory Create a new directory under version
svn mkdir http://URL/directory control.
svn move directory1 directory2 Rename or move a file or directory.
svn mv directory1 directory2 Moves/renames file/directory in
svn mv file-old-name file-new-name repository and in local work area.
Must perform svn ci file-new-
name after the move for changes to to
take place in repository.
svn revert filename Undo changes in local work files.
Throw away local changes.
svn resolved filename Run this command after resolving
merge conflicts. Next "commit" your
changes.
svn status Show status of file changes in current
svn status -u directory and recursively in directories
svn status -u . below.
svn status -uq . Show out of date file info: svn
status --show-updates

http://www.yolinux.com/TUTORIALS/Subversion.html Page 4 of 21
Subversion Commands and Scripts 18/07/2017, 19*46

(equivalent: svn status -u)


-u: Determines status by comparing
your local repository with the server
repository. Without this option, the
status shown will only be the changes
you have made in your local
repository.
-q: Quiet. Do not print "?: File/directory
not under version control" or "!:
File/directory missing" extraneous
information.

First collumn:

A: File to be added
C: Conflicting changes
D: File to be deleted
G: File to be merged with
updates from server
M: File has been modified
R: File to be replaced
G: File to be merged
X: Resource is external to
repository (svn:externals)
?: File/directory not under
version control
!: File/directory missing
~: Versioned item obstructed by
some item of a different kind.

Second collumn: Modification of


properties
' ' no modifications. Working
copy is up to date.
'C' Conflicted
'M' Modified
'*' Local file different than
repository. A newer revision
exists on the server. Update will
result in merge or possible
conflict.
Third collumn: Locks
' ' not locked
'L' locked
'S' switched to a branch

(svn 1.7+) svn relocate http://server/new- Switch your local working copy to
path mirror a new repository branch instead
(svn 1.6-) svn switch http://server/new- of main trunk or previous branch. Also
branch allows you to point your repository to a
svn switch --relocate new path on the server if the server
http://server/old-path path changes since you performed a
http://server/new-path check-out. Use "relocate" when using
Subversion version 1.7 or later.

svn update Migrate all updates from Subversion


svn update filename repository to your local copy

http://www.yolinux.com/TUTORIALS/Subversion.html Page 5 of 21
Subversion Commands and Scripts 18/07/2017, 19*46

svn update -r458 filename (recusively for all files in the current
svn update --ignore-externals ./ directory and all below it). If there have
been updates to the svn repository
since you downloaded the files,
subversion will give you the
opportunity to merge. Status of files
will use the coding as stated above for
"status". Files marked with a "C"
(conflict) should be merged of
reverted. If merged then one can
perform a "resolve" and then a "check-
in".
If a file name is specified, only that file
is updated.
Can also syncronize to a specified
revision given by -r.
Use --ignore-externals to avoid the
slow processing of externals to a
potentially slow distant internet server.
Where RevisionNumber is:

HEAD: The latest revision in the repository.


BASE: The "pristine" revision of an item in a working copy. Matches checked out
version before any modifications.
COMMITTED: The last revision in which an item changed before (or at) BASE.
PREV: The revision just before the last revision in which an item changed. (Technically,
COMMITTED - 1.)

Example Session:
(Assumes that the repository has already been created. For Subversion repository creation
and Subversion server configuration, see the (YoLinux Subversion and Trac tutorial
(LinuxSubversionAndTracServer.html))
Checkout: svn checkout http://svnserver/repos/svn/trunk/Project1
Go to source code directory: cd Project1/src
Edit files:
vi file1.cpp
vi file2.cpp
Verify and test: make
We are ready to check-in the files into the Subversion repository.
Check repository and report on new revisions and changes others have checked in:
svn status -u .
After many long hours or days of editing and work, get updates others have made: svn
update

U file.h
C file1.cpp
G file2.cpp
? a.out

You will see:


U: File was updated with a newer version checked-in since your checkout.
G: Automatically merged with no conflicts.
C: Not merged due to conflicts. You made changes to the same section of code
as the update made by someone else since your checkout.
For each "conflicted" file there will be three new local files generated by "update":

http://www.yolinux.com/TUTORIALS/Subversion.html Page 6 of 21
Subversion Commands and Scripts 18/07/2017, 19*46

file1.cpp.mine (File - post editing)


file1.cpp.rold (BASE - pre editing)
file1.cpp.rnew (HEAD - Updated file from repository)
The file file1.cpp still exists but with svn conflict marker strings added in the file.
At this point, a check-in will fail until the merge is resolved.
Merge options:
Edit the file file1.cpp
Text markers are placed in the file to show the conflicts between the "HEAD" and
"mine" versions.
OR
tkdiff -conflict file1.cpp
OR
Use a GUI merge tool: kdiff3 file1.cpp.mine file1.cpp.rnew -o
file1.cpp
OR
Throw out your changes/abort: svn revert file1.cpp
No resolve or check-in necessary if file is reverted.
Verify and test, again: make
Notify Subversion that conflicts have been resolved: svn resolved file1.cpp
Note: This also removes the temporary files ".mine" and ".r###".
Check-in to Subversion repository: svn ci -m "Add comments here"
file1.cpp

Subversion Peg revisions:


Peg revisions are used so Subversion can find a previous version of a resource (file or
directory) if its' location was different than it is now. Peg revisions are that extra hint
Subversion needs to clear up ambiguity.

$ svn command -r OPERATIVE-REV item@PEG-REV

The default peg revision is BASE for working copy items and HEAD for repository URLs.
When no operative revision is provided, it defaults to being the same revision as the peg
revision.

The PEG-REV is specified if the resource (file/directory) in question use to appear in a


directory which is no longer in the same place or no longer exists. The "peg-revision" must be
specified so subversion can look at the directory in that revision so it can find the resource.

If a peg revision is specified without an operative revision, then the operative revision is
assumed to be the same as the peg revision.

For more see: http://svnbook.red-bean.com/en/1.5/svn.advanced.pegrevs.html


(http://svnbook.red-bean.com/en/1.5/svn.advanced.pegrevs.html)

Subversion Properties:
Files under revision control can include Subversion keywords which properties can be set
with the "propset" command. Keywords are substituted with the Subversion properties and
will not appear in the file until a commit is performed. Other properties are used to modify the
behavior of Subversion.

The following properties can be set on entities stored in Subversion:

Property Description
svn:ignore A newline separated list of file patterns to ignore. List of files/directories to be
ignored by svn status
svn:keywords Valid RCS style keywords are:
HeadURL - The URL for the head version of the object.

http://www.yolinux.com/TUTORIALS/Subversion.html Page 7 of 21

Você também pode gostar