SVN commands are usually helpful. If you do not know how to use the commands, you can easily obtain help information. For example, if you have a command SVN but do not know which sub-commands are available, you can query them as follows:
$ svn help
If you know the sub-commands, but do not know the usage of the sub-commands, you can also query:
$ svn help add
In addition, you may need to set the svn commit message editor, which can be handled by defining the environment variable svn_editor or visual or editor, for example:
$ export SVN_EDITOR=/bin/vi
This document uses HTTPS to access the version library. Other methods (such as file: //, SVN: //, http: //, SVN + SSH) the operation is basically the same.
Common commands of developers
(1) import the project
$ cd ~/project$ mkdir -p svntest/{trunk,branches,tags}$ svn import svntest https://localhost/test/svntest --message "Start project"...$ rm -rf svntest
Create a project svntest and create three subdirectories under the project: trunk, development trunk, branches, Development Branch, tags, and development phase tag. Import it to the version library test and remove svntest.
(2) Export a project
$ svn checkout https://localhost/test/svntest/trunk
Each developer must know how to specify the revision version number. The following are some reference examples. For details, refer to SVN references.
$ svn diff --revision PREV:COMMITTED foo.c# shows the last change committed to foo.c$ svn log --revision HEAD# shows log message for the latest repository commit$ svn diff --revision HEAD# compares your working file (with local changes) to the latest version# in the repository$ svn diff --revision BASE:HEAD foo.c# compares your “pristine” foo.c (no local changes) with the # latest version in the repository$ svn log --revision BASE:HEAD# shows all commit logs since you last updated$ svn update --revision PREV foo.c# rewinds the last change on foo.c# (foo.c's working revision is decreased)$ svn checkout --revision 3# specified with revision number$ svn checkout --revision {2002-02-17}$ svn checkout --revision {15:30}$ svn checkout --revision {15:30:00.200000}$ svn checkout --revision {"2002-02-17 15:30"}$ svn checkout --revision {"2002-02-17 15:30 +0230"}$ svn checkout --revision {2002-02-17T15:30}$ svn checkout --revision {2002-02-17T15:30Z}$ svn checkout --revision {2002-02-17T15:30-04:00}$ svn checkout --revision {20020217T1530}$ svn checkout --revision {20020217T1530Z}$ svn checkout --revision {20020217T1530-0500}
(3) Routine instructions
$ svn update$ svn add foo.file$ svn add foo1.dir$ svn add foo2.dir --non-recursive$ svn delete README$ svn copy foo bar$ svn move foo1 bar1$ svn status$ svn status --verbose$ svn status --verbose --show-updates$ svn status stuff/fox.c$ svn diff$ svn diff > patchfile$ svn revert README$ svn revert
When a conflict occurs, three files are generated:. Mine,. roldrev,. rnewrev. For example:
$ ls -lsandwich.txtsandwich.txt.minesandwich.txt.r1sandwich.txt.r2
To solve the conflict, modify the conflicting file sandwich.txt and run the following command:
$ svn resolved sandwich.txt
Method 2: Use the new version in the library to overwrite your changes:
$ cp sandwich.txt.r2 sandwich.txt$ svn resolved sandwich.txt
Method 3: undo your changes. In this way, you do not need to run the resolved subcommand:
$ svn revert sandwich.txtReverted 'sandwich.txt'$ ls sandwich.*sandwich.txt
Make sure that you can submit the application.
$ svn commit --message "Correct some fatal problems"$ svn commit --file logmsg$ svn commit
(4) Check version history
$ svn log$ svn log --revision 5:19$ svn log foo.c$ svn log -r 8 -v$ svn diff$ svn diff --revision 3 rules.txt $ svn diff --revision 2:3 rules.txt $ svn diff --revision 4:5 http://svn.red-bean.com/repos/example/trunk/text/rules.txt$ svn cat --revision 2 rules.txt $ svn cat --revision 2 rules.txt > rules.txt.v2$ svn list http://svn.collab.net/repos/svn$ svn list --verbose http://svn.collab.net/repos/svn$ svn checkout --revision 1729 # Checks out a new working copy at r1729…$ svn update --revision 1729 # Updates an existing working copy to r1729…
(5) other useful commands
svn cleanup
Clearing a failed transaction.
(6) branch and merge
Method 1 for creating a branch: Check and copy the branch, and then submit the copy.
$ svn checkout http://svn.example.com/repos/calc bigwcA bigwc/trunk/A bigwc/trunk/MakefileA bigwc/trunk/integer.cA bigwc/trunk/button.cA bigwc/branches/Checked out revision 340.$ cd bigwc$ svn copy trunk branches/my-calc-branch$ svn statusA + branches/my-calc-branch$ svn commit -m "Creating a private branch of /calc/trunk."Adding branches/my-calc-branchCommitted revision 341.
Method 2: directly copy a branch.
$ svn copy http://svn.example.com/repos/calc/trunk / http://svn.example.com/repos/calc/branches/my-calc-branch / -m "Creating a private branch of /calc/trunk."Committed revision 341.
After creating a branch, you can checkout the branch and continue your development.
$ svn checkout http://svn.example.com/repos/calc/branches/my-calc-branch
If you have already Checkout the trunk and want to switch to a branch for development, you can do the following:
$ cd calc$ svn info | grep URLURL: http://svn.example.com/repos/calc/trunk$ svn switch http://svn.example.com/repos/calc/branches/my-calc-branchU integer.cU button.cU MakefileUpdated to revision 341.$ svn info | grep URLURL: http://svn.example.com/repos/calc/branches/my-calc-branch
For commands for file merging, refer:
$ svn diff -r 343:344 http://svn.example.com/repos/calc/trunk$ svn merge -r 343:344 http://svn.example.com/repos/calc/trunk$ svn commit -m "integer.c: ported r344 (spelling fixes) from trunk."$ svn merge -r 343:344 http://svn.example.com/repos/calc/trunk my-calc-branch$ svn merge http://svn.example.com/repos/branch1@150 / http://svn.example.com/repos/branch2@212 / my-working-copy$ svn merge -r 100:200 http://svn.example.com/repos/trunk my-working-copy$ svn merge -r 100:200 http://svn.example.com/repos/trunk$ svn merge --dry-run -r 343:344 http://svn.example.com/repos/calc/trunk
The last command only performs the merge test and does not perform the merge operation.
Creating a tag is no different from creating a branch, but copying it to a different directory.
$ svn copy http://svn.example.com/repos/calc/trunk / http://svn.example.com/repos/calc/tags/release-1.0 / -m "Tagging the 1.0 release of the 'calc' project."$ lsmy-working-copy/$ svn copy my-working-copy http://svn.example.com/repos/calc/tags/mytagCommitted revision 352.
The latter method directly copies the local copy of work as a tag.
You can also delete a branch.
$ svn delete http://svn.example.com/repos/calc/branches/my-calc-branch /-m "Removing obsolete branch of calc project."
Common Management commands
(7) version Library Management
$ svnadmin help...$ svnadmin help create...$ svnadmin create --fs-type bdb /usr/local/repository/svn/test$ chown -R svn.svn /usr/local/repository/svn/test
Build a version library. The database type is bdb (using Berkeley dB as the repository). The database name is test.
The SVN version library can be stored in two ways: Based on Berkeley dB (bdb) or based on the file system (fsfs), the storage method can be specified through -- FS-type.
(8) query version Library Information
$ svnlook help...$ svnlook help tree...$ svnlook tree /usr/local/repository/svn/test --show-ids...
For more detailed commands, please refer to the svn official recommendation book (http://svnbook.red-bean.com /). This book has a Chinese version and is free of charge.