Detailed explanation of SVN commands under Linux

Common commands

1. Help command: help(h)

  • Command usage :svn help
  • Command abbreviation :svn h
  • Command explanation : Use this command to see all commands and abbreviations about svn. Sometimes that command is forgotten, you can look at it, it is very useful.

2. Add new files to the repository:add

  • Command usage :svn add xxx.txt
  • Command explanation : After this command is used, you have to use the svn ci xxx.txtcommand to submit it.
  • Example : svn add *.php(add all php files in the current directory)

3. Submit the changed files to the repository:commit(ci)

  • Command usage :svn commit -m "LogMessage" xxx.txt
  • Command abbreviation :svn ci -m "LogMessage" xxx.txt

4. Check out the file to the local:checkout

  • Command usage :svn checkout path(项目库的路径)
  • Command abbreviation :svn co path

5. Update version:update(up)

  • Command usage :svn update -r m path
  • Command abbreviation :svn up
  • Command explanation : The frequency of use of this command should be the highest. svn updateIf there is no directory or file later, the files and subdirectories in the directory will be updated to the latest version by default. 
    • -r: Specify which version to update to. Example: svn up -r 200 123.txt( 123.txtRestore the local file to the version 200)

6. View the log:log

  • Command usage :svn log xxx.txt
  • Command explanation : used to display the modification record of this file and the modification description of the modifier.

7. View file details:info

  • Command usage :svn info xxx.txt
  • Command explanation : This command will display the path, name, version number, type and other information of the current file .

8. Compare the differences:diff(di)

  • Command usage :svn diff -r m:n xxx.txt
  • Command abbreviation :svn di -r m:n xxx.txt
  • Command explanation : Compare the difference between version mand version n
    • -r : The two version numbers to be compared. Example: svn di -r 2:3 123.txt(see 123.txtthe 2version and the 3differences between the versions) .

9. Delete files:delete(del,remove,rm)

  • Command usage :svn delete path -m "DeleteMessage"
  • Command abbreviation :svn del/remove/rm path -m "DeleteMessage"
  • Command explanation : There are two ways to use this command. 
    • Remote deletion : svn delete svn://192.168.1.1/project_v1/123.php -m "delete test file"(After deleting in this way, the files in the version library will be deleted directly).
    • Submit for deletion : first svn delete 123.php, then svn ci -m "delete file"(this method is recommended).

 

 

Uncommon commands

10. Lock the file:lock

  • Command usage :svn lock -m "LockMessage" xxx.txt
  • Command explanation : mainly to prevent file conflicts.

11. Unlock the file:unlock

  • Command usage :svn unlock xxx.txt

12. Move files or rename files:move(mv,rename,ren)

  • Command usage :svn move -m "MoveMessage" xxx.txt
  • Command abbreviation :svn mv/rename/ren -m "MoveMessage" xxx.txt
  • Command explanation : Let's give two examples to understand this command more intuitively. 
    • svn move -m "rename file" 123.txt 456.txt( 123.txtRename the current directory 456.txt).
    • svn move -m "move file" 123.txt test/123.txt(Move the current directory 123.txtto the current subdirectory test).

13. List the files and directories belonging to the version library:list(ls)

  • Command usage :svn list path
  • Command abbreviation :svn ls
  • Command explanation : Display paththe files and directories belonging to the version library under the directory. If there is no pathparameter, the files and directories belonging to the version library in the current directory are displayed.

 

 

Detailed explanation of Linux SVN commands

 

1. Checkout the file to the local directory

        svn checkout  path (path is the directory on the server)
        For example: svn checkout svn://192.168.1.1/pro/domain
        Abbreviation: svn co

2. Add new files to the repository

        svn add  file
        For example: svn add test.php (add test.php)
        svn add *.php (add all php files in the current directory)

3. Submit the changed files to the repository

        svn commit  -m "LogMessage" [-N] [--no-unlock] PATH (If you choose to keep the lock, use the --no-unlock switch)
        For example: svn commit -m "add test file for my test" test .php
        abbreviation: svn ci

4. Lock/unlock

        svn lock -m "LockMessage" [--force] PATH
        例如:svn lock -m "lock test file" test.php
        svn unlock PATH

5. Update to a certain version

        svn update -r  m path
        For example:
        svn update If there is no directory later, all files in the current directory and subdirectories will be updated to the latest version by default.
        svn update -r 200 test.php (restore the file test.php in the version library to version 200)
        svn update test.php (update, synchronized with the version library. If it prompts expired when submitting, it is because of conflicts and needs Update first, modify the file , then clear svn resolved , and finally submit commit)
        Abbreviation: svn up

6. View file or directory status

        1) svn status  path (the status of files and subdirectories in the directory, the normal status is not displayed)
            [?: not under svn control; M: content is modified; C: conflict occurs; A: scheduled to be added to the repository; K: Locked]
        2) svn status -v  path (display file and subdirectory status) The
            first column remains the same, the second column displays the working version number, and the third and fourth columns display the last modified version number and the person who modified it.
        Note: The three commands svn status, svn diff and svn revert can also be executed without a network, because svn keeps the original copy of the local version in the local .svn.
        Abbreviation: svn st

7. Delete files

        svn delete  path -m "delete test fle"
        For example: svn delete svn://192.168.1.1/pro/domain/test.php -m "delete test file"
        or directly svn delete test.php and then svn ci -m ' delete test file', this
        abbreviation is recommended : svn (del, remove, rm)

8. View the log

        svn log  path
        For example: svn log test.php shows all the modification records of this file, and the changes of the version number

9. View file details

        svn info  path
        For example: svn info test.php

10. Compare the differences

        svn diff  path (compare the modified file with the basic version)
        For example: svn diff test.php
        svn diff  -rm:n path (compare the difference between version m and version n)
        For example: svn diff -r 200:201 test.php
        abbreviation : Svn di

11. Merge the differences between the two versions into the current file

        svn merge -r  m:n path
        For example: svn merge -r 200:205 test.php (Merge the differences between version 200 and 205 into the current file, but generally conflicts will occur and need to be dealt with)

12. SVN help

        svn help
        svn help ci

------------------------------------------------------------------------------

The above are commonly used commands, here are a few less frequently used commands

------------------------------------------------------------------------------

13. List of files and directories under the repository

        svn list  path
        displays all files and directories belonging to the version library in the path directory.
        Abbreviation: svn ls

 

14. Create a new directory under version control

        svn mkdir : Create a new directory under version control.
        Usage: 1. mkdir PATH... 2. mkdir URL... to create a version controlled directory. 1. Every directory specified by the working copy PATH will be created on the local side, and a new schedule will be added for the next submission. 2. Each directory specified by URL will be created in the warehouse by submitting it immediately. In both cases, all intermediate directories must exist in advance.
                
       
       
       
       

 

15. Restore local modifications

        svn revert : restore the original unchanged working copy file (restore most of the local modifications). revert:
        Usage: revert PATH...
        Note: This subcommand will not access the network and will resolve the conflict. But it will not restore the deleted directory

 

16. Change of code base URL

        svn switch (sw):  Update the working copy to a different URL.
        Usage: 1. switch URL [PATH]
                 2. switch --relocate FROM TO [PATH...]

        1. Update your working copy and map it to a new URL. Its behavior is very similar to "svn update". It will also merge files on the server with local files. This is a method of mapping a working copy to a branch or tag in the same warehouse.
        2. Rewrite the URL metadata of the working copy to reflect the pure URL changes. When the root URL of the warehouse changes (for example, the project name or host name changes), but the working copy is still mapped to the same directory of the same warehouse, use this command to update the correspondence between the working copy and the warehouse.

 

17. Resolve conflicts

        svn resolved:  Remove the "conflict" status of the directory or file of the working copy.
        Usage: resolved PATH...
        Note: This subcommand does not resolve conflicts or remove conflict flags according to the syntax; it just removes conflicting related files, and then allows PATH to be submitted again.

 

18. Output the content of the specified file or URL.

        svn cat  target [@version]... If a version is specified, it will be searched from the specified version.
        svn cat -r PREV filename> filename (PREV is the previous version, you can also write the specific version number, so that the output result can be submitted)

 

19. Find all the remaining log files in the working copy and delete the locks in the process.

When Subversion changes your working copy (or any information in .svn), it will be as careful as possible. Before modifying anything, it writes the intention to the log file, then executes the commands in the log file, and then Delete the log file, which is similar to the file system architecture of the ledger. If the Subversion operation is interrupted (for example: the process is killed, the machine dies), the log file will be saved on the hard disk. By re-executing the log file, Subversion can complete the last operation started, your working copy You can return to a consistent state.

This is what svn cleanup does: it finds all the remaining log files in the working copy and removes the locks in the process. If Subversion tells you that part of your working copy is "locked", you need to run this command. Similarly, svn status will use L to display locked items:

$ svn status
L somedir
M somedir/foo.c

$ svn cleanup
$ svn status
M somedir/foo.c

 

20. Copy a user's unversioned directory tree to the repository.
The svn import command is the fastest way to copy a user's unversioned directory tree to the repository. If necessary, it also creates some intermediate files.

$ svnadmin create /usr/local/svn/newrepos $ svn import mytree file:///usr/local/svn/newrepos/some/project Adding mytree/foo.c Adding mytree/bar.c Adding mytree/subdir Adding mytree/subdir/quux.h Committed revision 1.

In the previous example, the directory mytree will be copied to some/project of the repository:

$ svn list file:///usr/local/svn/newrepos/some/project bar.c foo.c subdir/

Note that after the import, the original directory tree is not converted into a working copy. In order to start working, you still need to run svn checkout to export a working copy.

Attachment:
You can add email notifications for SVN  through Subversion's Hook script. 
After compiling and installing Subversion, there is a Perl script of comm-email.pl under the tools of the source code. There is a Perl script in your archive directory. A hooks directory, enter the hooks directory and rename post-commit.tmpl to post-commit and give it executable permissions. 
Change the post-commit script and add the absolute path of the comm-email.pl script, otherwise SVN cannot find comm-email.pl 

REPOS="$1" 
REV="$2" 
/usr/local/svn /resp/commit-email.pl "$REPOS" "$REV" [email protected] [email protected] 
#log-commit.py --repository "$REPOS" --revision "$REV" 

The last line is for logging. I don’t use this function, so I commented it out.

Guess you like

Origin blog.csdn.net/qq_14874791/article/details/109114474