Build a quick tutorial on using SVN

Source: Internet
Author: User
Tags subversion client svn update
ArticleDirectory
    • Setting up a quick tutorial on using SVN can help you familiarize yourself with the basic configurations and operations of subversion.
Setting up a quick tutorial on using SVN can help you familiarize yourself with the basic configurations and operations of subversion.

First, install the Subversion client correctly.ProgramSVN and management tool svnadmin. Suppose you use subversion 1.2 or an updated version (you can run SVN -- version to check the version ).
All version data of subversion is stored in the central version database. Therefore, we need to create a version database first:

$ Svnadmin create/var/SVN/Repos
$ Ls/var/SVN/Repos
Conf/Dav/DB/format hooks/Locks/readme.txt

This command creates a new directory/var/SVN/repos and a subversion version repository. This directory stores database files (there are other configuration files ). If you look at it, you will not find your versionized file.
There is no concept of "project" in subversion. The Subversion version Version library is just a virtual version-based file system that stores any files you want to store. Some administrators prefer to create an independent version library for each project, while others prefer to store multiple projects in different directories of the same version library. The two methods have their own advantages. Either way, the version library is only responsible for managing files and directories, while the "project" is a concept specified by humans. Therefore, although the word "project" is everywhere in the book, remember that we are only talking about some specific directories (or a group of directories) in the version library ).

In this example, we assume that some entries (a group of files and directories) need to be imported to the Subversion database ). Next, we need to sort these entries into a directory named myproject (or any other directory. In this directory, create three top-level subdirectories: branches, tags, and trunk. Save all versioning data to the trunk directory and leave the branches and tags directories empty:

/Tmp/myproject/branches/
/Tmp/myproject/tags/
/Tmp/myproject/trunk/
Foo. c
Bar. c
Makefile
...

The three sub-directories branches, tags, and trunk are not required by subversion. However, this is a habit of subversion, so we should follow this convention. After preparing the data, you can use the svn import command ("import data to your version library") to import it to the version Library:

$ SVN import/tmp/myproject file: // var/SVN/repos/myproject-M "Initial import"
Adding/tmp/myproject/branches
Adding/tmp/myproject/tags
Adding/tmp/myproject/trunk
Adding/tmp/myproject/trunk/Foo. c
Adding/tmp/myproject/trunk/bar. c
Adding/tmp/myproject/trunk/makefile
...
Committed Revision 1.
$

Now the version library has saved the data in the directory. As mentioned above, directly viewing the version library does not see files and directories, and they are stored in the database. However, the Virtual File System of the version library contains a top-level directory named myproject, which stores all the data.
Note that the/tmp/myproject directory we created at the beginning has not changed, and subversion does not care about it (in fact, this directory can be completely deleted ). To start using version library data, we also need to create a new "working copy" for storing data, which is a private workspace. Check the "myproject/trunk" working copy from the Subversion library as follows:

$ SVN checkout file: // var/SVN/repos/myproject/trunk myproject
A myproject/Foo. c
A myproject/bar. c
A myproject/makefile
...
Checked out Revision 1.

Now, the myproject directory contains a personal copy of the version database data. We can edit the file in the working copy and submit the modification to the version library.

    • Go to the working copy directory and edit the content of a file.
    • Run SVN diff to view your changes in the standard format.
    • Run SVN commit to submit your modifications to the version library.
    • Run SVN update to update your working copy to the "latest" version of the version library.

There are many methods to start:
Svnserve-d-r/home/Neo/SVN/Server/repos/(or svnserve-I)
// The-D parameter enables svnserve to run in the background, and the-R parameter limits the addresses that the repo can access on the network.
// If other computers on the network want to checkout this server, you only need to enter SVN checkout

SVN: // 192.168.1.188/helloworld
// The actual location of the repo on the local machine is/home/Neo/SVN/Server/repos/helloworld.

Check whether it can be started:
Netstat-A | grep SVN
PS-A | grep SVN

# Svnadmin create ##
Note: svnadmin is a server-side command, and svnadmin create is a sub-command.
Create a working copy because svnadmin directly accesses the version Library (so it can only be used on the machine where the version library is stored)

It accesses the version library through the path instead of the URL.
Instead of creating an intermediate directory
$ Svnadmin create/SVN/repos/

# SVN import ##
Note: It is the fastest way to import unversionized files to the version library. An intermediary directory will be created as needed.
SVN import does not require a working copy. Your file will be directly submitted to the version library,
This is usually used when you want to add a group of files to the Subversion library.
$ SVN import/SVN/source/file: // SVN/repos/project1-M "Initial import"

# SVN list ##
Views the version library directory.
$ SVN list file: // SVN/repos/project1

# SVN update ##
Note: synchronize your work copy with the latest version, which will be changed to work after the last update by you and all others.

Copy
$ SVN update

# SVN checkout ##
Note: Check out and obtain a private copy (working copy) of the project)
$ SVN checkout http://svn.example.com/repos/calc
$ SVN checkout file:/var/SVN/Repos
$ SVN checkout file: localhost/var/SVN/Repos
$ SVN checkout SVN: 192.168.10.183/Repos
Obtain the snapshot of the old version library. You can use the svn update and SVN checkout -- Revision (-R) options to complete

Working Copies: "Time goes backwards"
Check out a new working copy on r1729
$ SVN checkout-r 1729
Update an existing working copy, r1729
$ SVN update-r 1729
Put your work copy to subv instead of trunk as before. If subv does not exist, it will automatically create

Create
$ SVN checkout http://svn.collab.net/repos/svn/trunk subv

# SVN add ##
NOTE: If foo is a directory, all contents in Foo will also be scheduled to increase. If you only want to add foo
Use the -- Non-recursive (-N) parameter.
Add the file, directory, or symbolic link Foo to the version library.
$ SVN add foo

# SVN Delete ##
Note: delete the file, directory, or symbolic link Foo from the version library. If foo is a file or symbolic link, it will immediately
Delete from the work copy. If foo is a directory, it will not be deleted, but is scheduled to be deleted by subversion. When you mention

Submit for repair
After modification, Foo will be deleted in your working copy and version library.
$ SVN Delete foo

# SVN copy ##
Note: Create a new entry Bar as a replica of Foo and add bar for automatic scheduling. When you submit the entry next time

Bar
Added to the version library. This replication will record the history (recorded in the way From Foo ). If no --

Parents,
SVN copy does not create an intermediary directory.
$ SVN copy Foo bar

# SVN move ##
Note: You must tell subversion about anything you do. For example, if you want to copy or move a working copy
File, you should use SVN copy or SVN move, instead of using the Copy command of the Operating System
This command is exactly the same as running SVN copy Foo bar; SVN Delete Foo, and bar is used as the copy of foo
Bay scheduling is added, and foo has been scheduled to be deleted. If -- parents is not passed, SVN move does not create an intermediary directory.
$ SVN move foo bar

# SVN diff ##
Note: Check the modification details. You can use SVN status, SVN diff, and SVN without a network.

Revert.
Subversion uses the original version cache in the. SVN management area.
Another way to check the modification is the svn diff command. You can use SVN diff without parameters to precisely find out your

What
Modify:
$ SVN diff
The SVN diff command outputs information by comparing your files with the "original" files stored in. SVN.

The file will display
Displays all added text. All files to be deleted are displayed.
The output format is the unified differential format. Add "-" before the row to be deleted, and add "+" before the row to be deleted. SVN diff life

Ling also beat
Print the location information required by the file name and patch, so you can redirect a different file to generate a "patch"

:
$ SVN diff> patchfile
If you want different output formats, you can use
-- Diff-cmd specifies an external Comparison Program and uses the -- Extensions (-x) option to pass other parameters. For example

,
Check the local modification of the local file Foo. C and ignore the case sensitivity differences. You can run
$ SVN diff -- diff-CMD/usr/bin/diff-X "-I" foo. C.
If you pass a -- Revision (-R) parameter, your working copy will be compared with the specified version in the version Library:
$ SVN diff-R 3 rules.txt
If two versions separated by colons are passed through -- Revision (-R), the two versions will be directly compared
$ SVN diff-R 2: 3 rules.txt
Finally, even if you do not have a working copy on the local machine, you can compare the version of the version library. You only need to enter

Enter the appropriate URL:
$ SVN diff-C 5 http://svn.example.com/repos/example/trunk/text/rules.txt

# SVN revert ##
Note: cancel local modification and use the "original" Copy cached in the. SVN directory to restore the file to the unmodified state. In addition,

SVN
Revert can cancel any operation you want to do-for example, you no longer want to add a new file
$ SVN revert readme

# SVN status ##
### SVN status -- verbose ##
Note: All changes will be made to you-instead
You need to access the version library and will not merge the changes without your knowledge with other users.

If you run the svn STATUS Command without parameters in the top-level directory of the working copy, it will detect all files or

Directory
Outgoing Modification
$ SVN status
If you pass a path to SVN status, it only gives you information about this project:
$ SVN status stuff/fish. c
SVN status also has a -- verbose (-v) option, which can display all projects in the working copy, even if not changed

Of
$ SVN status-V
All the above SVN status calls do not contact the version library-only compare with the raw data in. SVN. Last

, Use
-- Show-Updates (-u) option, which will contact the version library to add new information for outdated data:
$ SVN status-u-V

# SVN resolved ##
### SVN resolved mk-bcc.bat ##
Note: delete the three temporary files and files of the accepted version due to the conflict. When you specify the -- accept option, and

Subversion no longer considers the file in a conflicting state
$ SVN resolve -- accept working sandwich.txt
Discard your changes and receive new revisions
$ SVN resolve -- accept theirs-full sandwich.txt

# SVN commit ##
Note: Submit (atomic operation) Your modifications to the version library.
$ SVN commit button. C-M "fixed a typo in button. C ."
However, if you write log information as part of your work, you may want to tell subversion to use a file

Name
To obtain the log information, use the -- file (-f) option:
$ SVN commit-F logmsg

# SVN cleanup ##
Note: It will search for your working copy and running log and delete any working copy of the lock in the process. If the Subversion used

Tell you that some parts of your work copy are "locked ",
This is the command you should execute. The SVN status will display a lock item next to L.
$ SVN status
L somedir
M somedir/Foo. c
$ SVN cleanup
$ SVN status
M somedir/Foo. c

# SVN log ##
Note: Check log history
$ SVN log-r 5:19 # Shows logs 5 through 19 in chronological order
$ SVN log-r 19:5 # Shows logs 5 through 19 in reverse order
$ SVN log-R 8 # Shows log for revision 8
You can also check a file or directory in the log history. For example
$ SVN log Foo. c
$ SVN log http://foo.com/svn/trunk/code/foo.c

# SVN cat ##
Note: output the content of a specific file or URL. If you only want to check a previous version and do not want to check their differences,

Use SVN cat
$ SVN cat-R 2 rules.txt
You can redirect the output to a file:
$ SVN cat-R 2 rules.txt> rules.txt. v2

# SVN list ##
Note: SVN list can view files in the directory without downloading files to the local directory:
$ SVN list http://svn.collab.net/repos/svn
If you want to view the details, you can use the -- verbose (-v) parameter:
$ SVN list-V http://svn.collab.net/repos/svn

# SVN switch ##
Note: update the working copy to another URL, alias SW.
If your current directory vendors branches to vendors-with-fix, you want to move to that branch:
$ SVN switch http://svn.red-bean.com/repos/branches/vendors-with-fix.
After switching back, you only need to provide a URL for your original work copy:
$ SVN switch http://svn.red-bean.com/repos/trunk/vendors.

### Four states of working copy ###
(1) not modified and current
The file is not modified in the working directory and is not modified after the working version and submitted to the version library. SVN commit operation not performed
SVN update does nothing.

(2) Locally modified and current
The working directory has been modified and has not been modified since the basic revision and submitted to the version library. Local modifications are not submitted, so
SVN commit is successfully submitted, and SVN update does not do anything.

(3) The local device has not been modified and is out of date.
This file is not modified in the working directory, but has been modified in the version library. This file will be updated to the latest version,
Became the current public revision. SVN commit does not do anything. SVN update will get the latest version to work.
As a copy.

(4) local modification and expiration
This file has been modified in the working directory and version library. A svn commit will fail.
New: The SVN update command merges public and local modifications. If the Subversion cannot be completed automatically, the user will
Conflict.

### What are in directory. SVN ###
Any directory in the working copy contains a. SVN management area. The list operation usually does not display this directory,
It is still a very important directory. No matter what you do, do not delete or change anything in this management area,
Subversion uses it to manage work copies.
If you accidentally delete the sub-directory. SVN, the simplest solution is to delete the contained directory (delete a common file system ).
And then run SVN update in the parent directory. The Subversion client will download and delete
And contains the new. SVN directory.

## the typical work cycle is as follows: ##< br> 1. Update your work copy.
SVN update
2. modify
SVN add
SVN Delete
SVN copy
SVN move
3. check and modify
SVN status
SVN diff
4. some modifications may be canceled
SVN revert
5. resolve Conflicts (merge others' modifications)
SVN update
SVN resolve
6. submit your modifications
SVN commit

# The following are examples of keywords in the revised version :##
$ SVN diff-r PREV: committed Foo. c
# Shows the last change committed to foo. c
$ SVN log-r head
# Shows Log message for the latest repository commit
$ SVN diff-r head
# Compares your working copy (with all of its local changes) to
# Latest version of that tree in the repository
$ SVN diff-r base: Head Foo. c
# Compares the unmodified version of foo. C with the latest version
# Foo. c In the Repository
$ SVN log-r base: Head
# Shows all commit logs for the current versioned directory since you
# Last updated
$ SVN update-r Prev Foo. c
# Rewinds the last change on foo. C, decreasing Foo. C's working Revision
$ SVN diff-r base: 14 Foo. c
# Compares the unmodified version of foo. C with the way Foo. c looked in revision 14

# When you specify a date, the subversion will find the latest version near this date in the version library, and

continued operation: #
$ SVN log-r {2006-11-28}
$ SVN checkout-r {2006-02-17}
$ SVN checkout-r {}
$ SVN checkout-r {15:30:00. 200000}
$ SVN checkout-r {""}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.