Subversion

version-control

Articles
Resources

Distributed Subversion
Subversion Modules
Branching and Tagging
Release Management
Features (compared to CVS)
Best Practices
Mixed Revisions
Diff formats
FAQs
Global Revision Numbers and Mixed Revisions Working Coy
Subversion Properties
Administration, Configuration, and other management tasks
Global Revision Number

How can we create a new repository?

cd /Users/khaidoan/doNotDelete
mkdir SubversionRoot/
svnadmin create /Users/khaidoan/doNotDelete/SubversionRoot/ProjectName

svn import InitialFolderName file:///Users/khaidoan/doNotDelete/SubversionRoot/ProjectName/trunk -m "Initial import"
svn list file:///Users/khaidoan/doNotDelete/SubversionRoot/ProjectName

Note that after the import is finished, the original tree is not converted into a working copy. To start working, you still need to svn checkout a fresh working copy of the tree.

How can we ignore all files in a given directory?

svn propset svn:ignore "*" dirname --recursive (Ignore all files in a directory)

svn propset svn:ignore --file /tmp/svnignore --recursive . (The content of /tmp/svnignore is *.pyc)
svn propset svn:ignore "*" --recursive dirname (Ignore all files in a directory)

How can we determine if a file was ever committed into subversion?

svn log -v -q > out

The above command list all the log messages along with all the files that were modified, added, or deleted as part of each previous commits and direct the output into a file. By examining the content of this file, we determine whether this file as ever committed into subversion.

How can we find files that were modified in a branch after the branch was created?

svn log -v -q --stop-on-copy > out
sort out > out2
uniq out2 > out3

How can we compare two directories from command line (verify that I / subversion did not miss any revision)?

diff -rwbB --strip-trailing-cr --exclude=bin --exclude=.svn qstrunk qsmarch

How can we find files that were part of a particular check-in?

svn log -v -q -r rev

How can we find the history of a file (how to tell whether the current branch was created from the trunk, or from another branch)?

svn log --stop-on-copy -v filename

Look for information inside the paranthesis.

What is the purpose of the "svn cat" command?

Retrieves a file as it existed in a particular revision number and displays it on your screen.

What happen when a single revision number is supplied for the "svn diff" command?

If we pass a single revision number for the —revision (-r) option of the "svn diff" command, your working copy is compared to the specified revision in the repository.

What happen when a range of revision numbers is specified for the "svn diff" command?

If a range of revision number (separated by a colon) are passed via —revision (-r), the two revisions are directly compared.

What happened when we do not specify a revision number for the "svn diff" command?

Subversion compare local modification in the working copy.

How can we check out a copy of the trunk into a directory name trunk (the directory name is optional)?

svn checkout http://svn.collab.net/repos/svn/trunk trunk

How can we check out a copy of the trunk (at a specific revision number)?

svn co -r XXXX http://svn.collab.net/repos/svn/trunk trunk

How can we check out a copy of the trunk and specifying the name of the local folder (to be created) for the working copy?

svn co -r XXXX http://svn.collab.net/repos/svn/trunk folderName

How can we checkout sub-directory?

svn co http://svn.collab.net/repos/svn/trunk/dirname

How can we diff (ignoring white space)?

svn diff -r r1:r2 --extensions '--ignore-space-change --ignore-all-space --ignore-eol-style --unified'

How can we use an external diff program?

svn diff -r 1488:1493 URL --diff-cmd /usr/bin/diff --extensions '-bc'

How can we use an external diff program during merging (merge but ignore changes in white space)?

svn merge -r 1488:1493 URL  --dry-run --diff3-cmd /usr/bin/diff3 --extensions '-w'

How can we list all the files that were modified in your working copy?

svn st

How can we find out which files will be updated when we do "svn update"?

svn st --show-updates

Files that will be updated are marked with an asterisk.

How can we move files around?

svn mv foo.c bar.c

How can we revert your change?

svn revert filename

How can we have a mixed-revision tag or branch?

You are not limited to tagging all files in the same revision in Subversion. If you need to make a mixed-revision tag or branch, you can always copy a working copy to a URL:

svn copy -m "comment" . URL

How can we move files / directories?

svn move

What is the purpose of "svn status -v"?

"svn status -v" will show you the status of every item in your working copy, even if it has not been changed. This is the "long form" output of "svn status". The letters in the first column represent that status code (refer to "svn help status" for detail meaning). The second column shows the working revision of the item. The third and fourth columns show the revision in which the item last changed, and who changed it.

How can we make a patch file?

svn diff > filename

Subversion uses its internal diff engine, which produces unified diff format, by default. If you want diff output in a different format, specify an external diff program using —diff-cmd and pass any additional flags that it needs via the —extensions (-x) option.

What happen to a file that was previously marked as "containing conflict" after you use the "svn revert" command?

If you decide that you want to throw out your changes, and start your edits again (whether this occurs after a conflict or anytime), just revert your changes. When you revert a conflicted file, you don't have to use "svn resolve". The file now has latest change (at the time of the merge).

If we have been editing log message in a text editor while we are working on the project, how can we use this file as our commit comment?

svn commit -F logfilename

If we are in our editor writing a commit message and we decide to cancel our commit, what can we do?

We can just quit the editor without saving the log message. If we already saved our commit message, simply delete all the text, save again, and then abort.

What is the meaning of revision keyword HEAD?

The revsion keyword / specifier HEAD refers to the latest (or the youngest) revision in the repository.

What is the meaning of the revision keyword BASE?

The revision keyword / specifier BASE refers to the revision number of an item in a working copy. If the item has been locally modified, this refers to the way the item appears without those local modifications.

What is the meaning of the revision keyword COMMITTED?

The revision keyword / specifier COMMITTED refers to the most recent revision prior to, or equal to, BASE, in which an item changed.

What is the meaning of the revision keyword PREV?

The revision keyword / specifier PREV refers to the revision immediately before the last revision in which an item changed. This boiled down to COMMITTED - 1.

PREV, BASE, and COMMITTED revision keywords are used only when referring to a working copy path. They are not applicable to repository URLs. HEAD, on the other hand, can be used in conjuction with both working copy path and repository URL path.

How can we show the last change committed for a file?

svn diff -r PREV:COMMITTED filename

The revision specifier PREV and COMMITTED are only applicable for working copy path, and COMMITTED does not refer to the latest revision in the repository. Therefore, the above command show the last change on the file before you do "svn update". To see the latest change in the repository, you many need to update your working copy using "svn update", or you have to somehow find the latest revision number on the repository by using svn log (specifying a URL), and the use "svn diff" (specifying two revision number, and the repository URL)

How can we show the log message for the latest repository commit?

svn log -r HEAD

How can we compare your working copy (with all of its local modifications) to the latest revision of that tree in the repository?

svn diff -r HEAD

How can we compare the unmodified version of foo.c with the latest revision of foo.c in the repository?

svn diff -r BASE:HEAD foo.c

How can we show all commit logs for the current versioned directory since you last updated?

svn log -r BASE:HEAD

Why does "svn diff -r BASE:HEAD" not show any differences?

When your working copy is created from a branch, other developers committed code changes onto that branch, and you've fully updated your working copy with "svn up", the "svn diff -r BASE:HEAD" does not show any differences / changes from BASE to HEAD. For me, this was un-expected. But read the definition of "BASE" carefully.

I use to think of "BASE" and the revision that the branch was created. This is not always the case. The revision keyword / specifier BASE refers to the revision number of an item in a working copy. After we do "svn up", BASE essentially refers to the same revision as HEAD. If we want to see the changes that had been committed onto the branch, we need to find the specific revision numbers (using "svn log —stop-on-copy" and "svn info", and specify those revision numbers as arguments to "svn diff"), or we have to specify full URL (possibly have to be executed outside of the working copy)

How can we rewinds the last change on foo.c (decreasing the working revision for foo.c)?

svn update -r PREV foo.c

How can we compare the unmodified version of foo.c with the way foo.c looked in revision 14?

svn diff -r BASE:14 foo.c

How can we use dates to specify arbitrary revision (show me all the changes between these two dates)?

The -r option can also accept dates as input, wrapped in curly braces ({ and }). Subversion accepts the standard ISO-8601 date and time format, plus a few others:

svn checkout -r {2006-02-17}
svn checkout -r {15:30}
svn checkout -r {"2006-02-17 15:30"}
svn checkout -r {"2006-02-17 15:30 +0230"}

If you specify a single date as a revision without specifying a time-of-day (for example, 2006-11-27), you may think that Subversion should give you the last revision that took place on the 27th of November. Instead, you'll get back a revision from the 26th or even earlier. Subversion will find the most recent revision of the repository as of the given date. If you give a date without a timestamp, Subversion assume 00:00:00 so looking for the most recent revision won't return anything for the 27th. So, if you want to include the 27th in your search, you can either specify the 27th with a time stamp ({"2006-11-27 23:59"}), or just specify the next day.

This is because Subversion is a one-way-only time machine (it always look back, instead of looking forward as we might expect). So given a specific point in time, Subversion ask itself "what is the latest revision number it know about as of this given point in time?". As of the specific point in time, Subversion only know about things that happened in the past. Subversion does not look into the future.

What is Peg and Operative Revisions?

Assume that you've rename a file, and later on create another file with the same name, these two files might not be the same. Using "peg and operative" revisions, we can identify each object independently. The basic concept is to specify the revision at the time the object exist in the repository using the @ symbol:

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

item@PEG-REV identifies the unique object. The OPERATIVE-REV is the normal revision number (an argument for the command).

How can we get help?

svn help command

How can we find out the version of the svn client?

svn --version --quiet

How can we do initial import of files into the repository?

svn import /path/to/my/directory repositoryURL -m "Initial import"

After the import is finished, the original local directory is not converted into a working copy. To begin working on that data in a versioned fashion, you still need to create a fresh working copy of that tree from the repository.

If we say that a bug was fixed by revision 9238, how can we read more about the exact changeset that fixed the bug?

svn log -r 9238
svn diff -c 9238 to see the patch itself

How can we merge a specific changeset into your working copy?

Passing the -c 9238 to the svn merge command would merge changeset r9238 into your working copy.

Miscellaneous thoughts and info:

Having configurations in the code versus a separate repository maintained by operation team (password sensibility if you have contractors, prolifation of configurations, difficulties in managing configuration, having separate repository encourage communication but there is chance for mis-communication)

svn:mergeinfo property

svnmerge.py can track merges without the svn:mergeinfo support thus works for older Subversion client.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License