In a word, the script series temporarily backs up SVN-modified files.

Source: Internet
Author: User

Introduction

Usage scenarios:

I am in the development environment, using the SVN version management tool, and compared to git, if you sometimes change more files, but not all need to commit (or need to follow a case a commit to commit), then how to filter? Git uses git to add the file you specify, and then Git CI, but there's no way to do it with SVN, especially at the command line.

General Usage:
    1. Back up the entire directory that you have modified to complete

    2. Restore files or blocks of code that are temporarily not required for submission

    3. Submit this modification

    4. Overwrite other modifications of the backup back to the working directory

Sentence script usage:

Temp_dir=~/temp_ ' Date ' +%y-%m-%d ' && mkdir $TEMP _dir && svn st-q | awk ' {print $} ' | Xargs-i CP {}--parents $TEMP _dir/-V
The above script decomposition steps are:
    1. Create a variable to represent the name of the temporary folder and use the timestamp as part of the folder name
    2. Create the folder
    3. Filter out changed files (note that this is only for modified files and added files, if it is deleted, it cannot be temporarily recorded)
    4. Using awk to filter the output of the above SVN st-q, each line shows only the file name field
    5. Copy all changed files to the temporary folder you just created in the same way that you keep the directory structure
Date "+%y-%m-%d" description

Let's take a look at the description in the Man Handbook of Date:

Synopsis
Date [OPTION] ... [+format]

FORMAT controls the output. Interpreted sequences is:
%Y year
%m Month (01..12)
%d day of month (e.g., 01)

Our requirement here is to output this way in 2015-01-07, which can represent the date of the current operation, so use the date "+%y-%m-%d" command as described in the man manual to get the current date.
But while I was writing this blog, I looked at the man handbook in detail and found that there was actually another format character that would make it easier to complete the requirements:
%F full date; Same as%y-%m-%d

So, the original sentence script can be optimized to:

Temp_dir=~/temp_ ' Date ' +%f ' && mkdir $TEMP _dir && svn st-q | awk ' {print $} ' | Xargs-i CP {}--parents $TEMP _dir/-V

SVN st-q Description

In the same vein, take a look at the description of the St-q parameter in the SNV man manual:

Status (Stat, ST): Print the status of working copy files and directories.
-Q [--quiet]: Print Nothing, or only summary information

If you do not use the-q parameter, all files that are not versioned will be listed, including a large number of intermediate files (such as. O, temp files, and so on), and when you add the-q parameter, just list all the files that have changed, including additions, deletions, modifications, and so on.

Xargs-i description

Let's take a look at the description of the-I parameter in Xargs's Man manual:

-I. REPLACE-STR
Replace occurrences of Replace-str in the initial-arguments with names read from standard input. Also, unquoted blanks do not terminate input items;  Instead the separator is the newline character. Implies-x and-l 1.

-I[REPLACE-STR]
This option was a synonym For-ireplace-str if replace-str is specified, and for-i{} otherwise. This option is deprecated; Use-i instead.

Directly from the Man Handbook, not very good understanding, there is a blog "I parameter Xargs " Use the example to demonstrate the specific usage, you can go to a view.

After I use the-i parameter here, I replace the contents passed by the previous pipeline with {} for the CP operation.

CP--parents Description

Let's take a look at the description of the--parents parameter in the CP Man Manual:

--parents
Use full source file name under DIRECTORY

For this parameter there is also a blog "CP Auto-Create hierarchy example" Using the example demonstrates the specific use, you can go to a view.

I use the--parents parameter here to ensure that the copy of the past files can keep the directory structure, then when the copy back because the directory structure is consistent, you can directly overwrite the copy back.

Summarize

This one-sentence script uses the following knowledge:

    1. Setting and reading of temporary variables
    2. The date command displays the current date
    3. && Connecting multiple command executions
    4. mkdir command to create a folder
    5. SVN command displays a list of all changed files using a summary
    6. awk outputs the specified field for each row
    7. Xargs to replace each entry with the-I parameter
    8. Maintain directory structure when copying files with the CP--parents parameter

Using blogs to record is not only a sharing, but also a refinement for yourself. When each command is decomposed, it is found that some of them can be implemented in a better way, and if they are not recorded and shared, they will not be more optimized because they are sufficient.

"The gift rose, the hand is fragrant", sincerity does not bully me also!


One sentence of the script series of files that have SVN changed temporarily back up

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.