[Linux tool] svn command line instance, linuxsvn

Source: Internet
Author: User
Tags svn client

[Linux tool] svn command line instance, linuxsvn

  • Introduction

Why should I write so many articles about svn on the Internet? Because they are in-depth, tiled, non-classified, and theoretically impractical, they cannot be remembered after reading them.

This article first introduces the basic usage and then carries out instance drills. I don't want to be big but comprehensive. I just want to be familiar with it and use svn help to draw a different line (for example, many commands of-r parameters are available ). If you have an environment (don't forget to have a server), it may take 10 minutes to follow the instance.

Svn: a popular version management tool. Based on a svn server, developers can use their own computers to install svn clients, and then implement code hosting, Version Management, collaborative development, and other functions. The svn client on Windows has the famous TortoiseSVN, and the graphic interface is very useful. Many Linux releases usually install the svn command line Client by default (content described in this article ). Of course, in Linux, Eclipse tools also have GUI svn client plug-ins, which are also very useful.

Welcome to lovickie's blog http://www.cnblogs.com/lovickie

  • Svn command line usage classification Overview (optional parameters in)

PATH is both a directory and a file. PATH can be omitted in most commands. The default value is the current directory. Some commands can replace PATH with URLs.

-R parameters are available in most commands. The default value is-r BASE.

Welcome to lovickie's blog http://www.cnblogs.com/lovickie

  1.View

  Svn helpCMD # view the help of svn CMD. Note that CMD does not contain parameters such as-xx.

  Svn infoPATH # view detailed information (URL, author, BASE version number, modification time)

  Svn logPATH [-v] [-r HEAD/BASE/PREV/version number] # view the submission log.-v contains files and subfolders.

#-R specifies the version. The default value is-r BASE.

# The latest version of HEAD Server

# Latest version of BASE update or submission

# PREV previous version, BASE-1

  Svn catPATH/URL [-r version] # view the content,-r specified version

  Svn diPATH [-r version A] [-r version A: Version B] # di = diff, check the difference between version A and local, or the difference between version A and B

  Svn diPATH/URL-c Version B # B must be a number to view the differences between version B-1 and B

  Svn lsPATH [-v] # ls = list to view the list of included files and subfolders.-v contains the latest local submission records.

  Svn stPATH [-v] # st = state to view uncommitted local modifications.-v is similar to svn ls PATH-v.

# A add, D Delete, M modify, R replace, and C conflict

# I ignore ,? Not included ,! Abnormal modification, S Switching

 

  2.Management

  Svn coURL -- username NAME # co = checkout, check that the work is copied to the local directory

  Svn exportURL # export to the local directory, which is not copied. svn is not included in the directory.

# Failure if the current directory has a folder with the same name

  Svn importPath url-m'submit log' # import the local directory PATH to the URL. The PATH does not change to a working copy.

  Svn swURL # sw = switch: switches the current local directory to a URL copy.

  Svn lockPATH-m'submit log' # Locked to be changeable only by the current user

  Svn unlockPATH # unlock. Do not add the-m parameter.

 

  3.Modify

  Svn upPATH [-r version] # up = update, update to local, U updated, G merged

# If C conflicts, the conflicting file * will be modified, and the files *. rxxxx and *. r. mine will be added.

  Svn ciPATH-m' submit log '# ci = commit: submit local modifications to the server. You can also use double quotation marks to submit logs.

  Svn mkdirPATH # create a directory PATH and add it to Version Management

  Svn addPATH # Add PATH to Version Management

  Svn del(Rm) PATH # del = delete, rm = remove, remove PATH from version management and delete

  Svn cpOldpath newpath # cp = copy, copy

  Svn mvOldpath newpath # mv = move, move

  Svn revertPATH # undo local modification (but the deleted directory cannot be recovered)

  Svn resolvedPATH # indicates that the conflict has been resolved (not to resolve the conflict file *, but to delete *. rxxxx and *. r. mine)

 

  4.Set ignore attributes

   Svn propset svn: ignore"FILE" PATH # Set the FILE in the PATH directory to ignore

# Separate multiple files by carriage return. PATH cannot be omitted.

  Svn propedit svn: ignorePATH # edit the ignore list in the PATH directory

# Export SVN_EDITOR =/usr/bin/vim

  Svn pget svn: ignore# Read the ignore list of the current directory

  Svn plist# View the attributes of the current directory. If this parameter is set to ignore, svn: ignore is displayed.

Welcome to lovickie's blog http://www.cnblogs.com/lovickie

  • Svn command line example

Assume that http: // path is the original directory of the server.

Welcome to lovickie's blog http://www.cnblogs.com/lovickie

   1.Check the working copy path

  Svn coHttp: // path -- username lovickie # check that the job is copied to the local directory.

Cd path # The subdirectory of the cd path, the same below

Svn info

Svn log-v-r HEAD

Svn ls-v

 

  2.Create directory path/newdir

  2.1Method 1: directly operate the Server Directory

  Svn mkdirHttp: // path/newdir-m' create directory '# directly create a directory on the server

Cd path

  Svn up. # Update to local

  2.2Method 2: create a directory and submit it to the server after the local copy operation.

Cd path

  Svn mkdirNewdir # You can also mkdir newdir and svn add newdir

Svn st # display A newdir

  Svn ciNewdir-m' create a directory '# submit modifications

Svn st # No display, because all local modifications have been submitted

Svn st-v # display A newdir

Svn log-v-r HEAD # displays A newdir, 'create directory'

 

  3.Delete directory path/newdir/dir1

  3.1Preparations for deleting directories: create directories path/newdir/dir1 and path/newdir/dir1/a. c.

Cd path/newdir

Mkdir dir1

Vim dir1/a. c # Save and exit, the same below

Svn add dir1 # displays A dir1, A dir1/a. c

Svn ci-m' create the directory dir1 and file a. c'

  3.2Method 1: directly operate the Server Directory

  Svn delHttp: // path/newdir/dir1-m' Delete dir1' # Delete the directory directly on the server

Cd path/newdir

  Svn up# Update to local

  3.3Method 2

  Svn rmDir1

Svn st # display D dir1, D dir1/a. c

  Svn ci-M'delete dir1' # submit the modification

Svn st # No display

Svn st-v

Svn log-v-r HEAD

  Svn up# It is important to update the deleted directory information to the local device!

Svn st-v # display D dir1, D dir1/a. c

Svn log-v-r HEAD # display D dir1, D dir1/a. c, 'delete dir1'

  3.4After deleting a directory, svn up not only refreshes the status to the latest version, but also avoids "inexplicable" submission failures.

Cd path/newdir

Svn mkdir dir2

Svn ci-m' create dir2'

Pushd dir2

Vim B .C

Svn add B. c

Svn ci-m' adds B. c'

Popd

Svn del dir2

Svn ci-m' Delete dir2 '# error

Svn up

Svn ci-m' Delete dir2 '# submitted successfully

 

  4.Copy the path/newdir/dir3 directory and move the path/newdir/dir4 directory.

  4.1Prepare the copy Directory: Create the directory path/newdir/dir3 and path/newdir/dir3/c. c.

Cd path/newdir

Svn mkdir dir3

Vim dir3/c. c

Svn ci-m' create directory dir3 and file c. c'

  4.2Copy and move Directories

Cd path/newdir

  Svn cpDir3 dir4 # copy dir3 to dir4

Svn mv dir4 dir5 # failed. Unless submitted first, note that -- force does not work either.

Svn ci-m' copy dir3 to dir4'

  Svn mvDir4 dir5 # dir4 is successfully moved to dir5

Svn del dir5 # failed unless submitted first

Svn del dir5 -- force # dir5 is successfully deleted.

  Svn ci-M': dir4 is deleted in disguise'

 

  5.Undo local modification path/newdir/dir3

  5.1Preparation for unmodification: Assume that path/newdir/dir3/c. c has been created and submitted.

Svn ls path/newdir/dir3/c. c

  5.2Undo File Modification dir3/c. c

Cd path/newdir

Vim dir3/c. c # modify it as needed

Svn st # display M dir3/c. c

Svn revert # failure, incomplete Parameters

Svn revert. # successful, but the operation object is directory. Instead of file dir3/c. c

Svn st # still displays M dir3/c. c

  Svn revertDir3/c. c # undo dir3/c. c

Svn st # No display

  5.3Undo file Delete dir3/c. c

Cd path/newdir

Rm-f dir3/c. c

Svn st # Because svn rm is not used, it is displayed! Dir3/c. c

  Svn revertDir3/c. c # Delete dir3/c. c successfully

Svn st # No display

  5.4Undo directory Delete dir3

Cd path/newdir

Rm-rf dir3

Svn st # display! Dir3

Svn revert dir3 # failed. You cannot use revert to restore the deleted directory.

  Svn up# Update all directories and files that can be deleted from the server

Welcome to lovickie's blog http://www.cnblogs.com/lovickie

  6.Resolve the conflict path/newdir/dir3/c. c

  6.1Preparations for Conflict Resolution: Assume that path/newdir/dir3/c. c has been created and submitted.

Svn ls path/newdir/dir3/c. c

  6.2Resolve conflicts caused by submitting and deleting elsewhere

Cd A new local directory # note that the directory cannot contain dir3

Svn co http: // path/newdir/dir3

Svn del dir3/c. c

Svn ci-m' Delete dir3/c. c' elsewhere'

Cd path/newdir/dir3

Vim c. c # make any changes

Svn ci-m' I don't know c. c has been deleted elsewhere. I tried to submit a change to c. c '# failed

Svn log-v-r HEAD # display D c. c, 'delete dir3/c. c' elsewhere'

  Svn up

Svn st # display? C. c, that is, c. c is not included in version management.

Svn add c. c # resolve the conflict: Re-add c. c, so that another submitter is angry.

  Svn ci-M': Don't delete c. c anymore. '# If it still fails, someone else submits it first.

  6.3Resolve conflicts caused by submitting changes elsewhere

Cd A new local directory # note that the directory cannot contain dir3

Svn co http: // path/newdir/dir3

Vim dir3/c. c # modify as follows and add a new line: printf ("Modify elsewhere \ n ");

# Include <stdio. h> int main () {printf ("Modify elsewhere \ n"); return 0 ;}

Svn ci-m' modify dir3/c. c' elsewhere'

Svn info # display Version 2001

Cd path/newdir/dir3

Svn info # display version 2000

Vim c. c # modify as follows, and add two lines: printf ("local modification"); printf ("\ n ");

# Include <stdio. h> int main () {printf ("modify local"); printf ("\ n"); return 0 ;}

Svn ci-m' does not know that c. c has been modified elsewhere. Attempt to submit the modification to c. c '# failed

Svn log-v-r HEAD # displays M c. c, 'modify dir3/c. c' elsewhere. Note that the default value is-r BASE.

Svn cat c. c-r BASE # view the content of BASE = 2000

  Svn catC. c-r HEAD # view HEAD = Version 2001

Svn di-r BASE: HEAD #, showing the difference between BASE and HEAD

Svn di [-r BASE] # display the difference between BASE = 2000 and local modification

  Svn di-R HEAD # displays the differences between HEAD = 2001 and local modifications, as shown below:

Index: c. c =====================================--- c. c (Revised Version 2001) ++ c. c (Work copy) @-3, 5 + 3, 6 @ {-printf ("Modify elsewhere \ n"); + printf ("Modify locally "); + printf ("\ n ");}

  Svn up

Svn st # display? C. c. r2000: The latest BASE version that is updated or submitted locally.

#? C. c. r2001, the latest HEAD and printf ("Modify elsewhere \ n") on the server ");

  #? C. c. mine, local modification, printf ("local modification"); printf ("\ n ");

# C. c. Conflict file. If it is U update or G merge, it does not need to be resolved. The content of c. c is as follows:

# Include <stdio. h> int main () {<. mine printf ("local changes"); printf ("\ n "); ======= printf ("Modify elsewhere \ n"); >>>>>>>>. r2001 return 0 ;}

Vim c. c # manual modification to resolve conflicts

  Svn resolvedC. c # Delete c. c. * And mark that the conflict has been resolved.

Svn st # display M c. c

  Svn ci-M'resolve the c. c modification conflict '# generate version 2002

  6.4Svn di PATH-r A: B or-r A (B is local not submitted) or-c B (A = B-1) Output Format

Index: A different file c. c =====================================--- c. c (Revision A) ++ c. c (Revision B) @-3, 5 + 3, 6 @ # The following shows version A's 3 ~ Line 5: Version B's 3 ~ The same content of Line 6 AB-unique content of Version A + unique content of Version B

Note: When svn di [-r BASE] is displayed, --- (Revision 2000), ++ (working copy) is displayed );

When svn di-r BASE: HEAD is used, --- (working copy), ++ (Revision 2001) is displayed ).

"Work copy" has different meanings in the above two places!

Welcome to lovickie's blog http://www.cnblogs.com/lovickie

  7.Lock and unlock path/newdir/dir3/c. c

  7.1Lock preparation: Assume that path/newdir/dir3/c. c has been created and submitted.

Svn ls path/newdir/dir3/c. c

  7.2Lock and unlock

Cd path/newdir

  Svn lockDir3/c. c-m' user lovickie locks c. c' # locks

  Svn unlockDir3/c. c # unlock. An error occurred while adding-m.

 

  8.Export and Import

  8.1Export path/newdir

Cd A new local directory # Note that there cannot be newdir under this directory

   Svn exportHttp: // path/newdir [-r HEAD] # The newdir generated in the current directory does not contain. svn, but does not work.

  8.2Import path/newdir/dir6/d. c

Cd A new local directory

Mkdir dir6

Vim dir6/d. c

  Svn importDir6 http: // path/newdir-m' import the content in dir6 '# That is, only d. c is imported.

  8.3Import path/newdir/dir7

Cd A new local directory

Mkdir dir7

Vim dir7/e. c

  Svn importDir7 http: // path/newdir/dir7-m' import dir7' # imports dir7 and dir7/e. c

   8.4Verify import results

Cd path/newdir

Svn up # display A d. c, A dir7, A dir7/e. c

 

  9Switch the working copy path/newdir/dir8

  9.1Preparations for switching work copies: Assume that path/newdir/dir7/e. c has been created and submitted.

Svn ls path/newdir/dir7/e. c

   9.2Switch to work copy

Cd path/newdir

Mkdir dir8

Vim dir8/f. c

Svn add dir8

Svn ci-m'create dir8'

Cd dir8

  Svn swHttp: // path/newdir/dir7 # Switch the working copy of the local directory to dir7

Svn ls # display e. c

Svn st path/newdir # display S dir8

  9.3Restore original work copy (cannot revert)

Cd path/newdir

Rm-rf dir8

  Svn up

Svn ls dir8 # Show f. c

Welcome to lovickie's blog http://www.cnblogs.com/lovickie

  10Set ignore path/newdir/dir3

  10.1Preparations for setting ignore: Assuming path/newdir/dir3 has been created and submitted

Svn ls path/newdir/dir3

Cd path/newdir/dir3

Vim a. out

Vim a. o

Vim B. obj

Svn st # display? A. out ,? A. o ,? B. obj

  10.2Set ignore File

Cd path/newdir/dir3

  Svn propset svn: ignore"A. out

> *. O

> *. Obj "./# note that the last./or. Is not omitted. Separate multiple ignore files with carriage return (> automatically generated prompt)

Svn st # not displayed, indicating that the list is successfully ignored

  Export SVN_EDITOR=/Usr/bin/vim # Otherwise, svn propedit cannot be executed.

  Svn propedit svn: ignore./# Edit the ignore list of the current directory. Save and exit.

  Svn pget svn: ignore# Read the ignore list of the current directory and display a. out *. o *. obj

  Svn plist# Display svn: ignore

 

  11Svn merge)

This function is too wasteful and is not recommended when you are not fully familiar with it.

Welcome to lovickie's blog http://www.cnblogs.com/lovickie

  • Conclusion

There is something wrong or the description is unclear. Please leave a message saying that I will correct and improve it.

Related Article

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.