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:
Back up the entire directory that you have modified to complete
Restore files or blocks of code that are temporarily not required for submission
Submit this modification
- 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:
- Create a variable to represent the name of the temporary folder and use the timestamp as part of the folder name
- Create the folder
- Filter out changed files (note that this is only for modified files and added files, if it is deleted, it cannot be temporarily recorded)
- Using awk to filter the output of the above SVN st-q, each line shows only the file name field
- 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:
- Setting and reading of temporary variables
- The date command displays the current date
- && Connecting multiple command executions
- mkdir command to create a folder
- SVN command displays a list of all changed files using a summary
- awk outputs the specified field for each row
- Xargs to replace each entry with the-I parameter
- 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