Preparation before starting

Operating system: Windows

Tools:

  • Phpstorm or webstorm

  • Git for windows

  • TortoiseSVN

SVN 1.7 and later versions only create a. SVN directory in the root directory.

If you need to use the SVN command line, you need to select The Command Line Tools option when installing TortoiseSVN.

Both Git and SVN function as code versioning tools

If the version server uses SVN and you want to use Git locally, you can use Git and SVN together.

Git has its own git-SVN command as a bridge tool to Subversion. For details, see Git and Subversion.

In this article, you can use both Git and TortoiseSVN tools.

Since I prefer to use command-line tools, the following is based on the command line.

For ease of use, you can put the bin directories of Git and SVN in environment variables.

1. Pull code

Run Git Bash in the Git Bash window and pull the code from the SVN version server using SVN co http://svn/repo

2. Configure. Gitignore and. Svnignore

The.svn and.git directories are ignored in.gitignore and.svnIgnore, respectively.

SVN ignores files. Subversion ignores files and directories

3. Update and commit code locally and remotely

Update and commit code locally using Git Update and Git commit.

Update and submit code remotely using SVN UP and SVN CI.

ignore-on-commit

Sometimes, locally modified files do not want to be submitted to the version server. The code to be committed is added to the Changelist of Work. The code to be committed is added to the Changelist of ignore-on-commit. Only the Changelist of Work is committed.

The specific code is as follows:

D:\workspace\trunk>svn cl work . -R Skipped '.' Skipped 'src' Skipped 'src\conf' A [work] src\conf\db.properties Skipped  'src\java' D:\workspace\trunk>svn cl ignore-on-commit src\conf\db.properties D [work] src\conf\db.properties A [ignore-on-commit] src\conf\db.properties D:\workspace\trunk>svn status --- Changelist 'work': src\java\com\corp\sample\Main.java M src\java\com\corp\sample\view\View.java src\resource\icon.ico --- Changelist 'ignore-on-commit': M src\conf\db.properties D:\workspace\trunk>svn commit --cl work -m "fixed refresh issue" Sending src\java\com\corp\sample\view\View.java Transmitting file data .done Committing transaction... Committed revision 9.Copy the code

SVN: Is there a way to mark a file as “do not commit”?

The permission of our local code submission is controlled, and the code can only be submitted through patch. Therefore, we can type patch with the set changelist as follows: SVN diff –cl work > fixbug. patch.

Configuration phpstorm

Terminal Tool Configuration

On Windows, phpStorm uses cmd.exe as the terminal tool by default. CMD cannot run bash files, so change phpstorm’s terminal tool to Git bash. The steps are as follows:

In PHPStorm, go to File–>Settings–>Tools–>Terminal

The paths in the red box must be marked with double quotation marks, or an error will be reported.

Shortcut Tool Configuration

In PHPStorm, you configure the necessary shortcuts to improve your productivity.

For example, in one of my projects, different directories are code pulled from multiple version servers. If I want to update some code, I need to go into a deep directory to execute SVN UP. If the shortcut tool is configured, I just need to use the shortcut key Shift+Ctrl+A to call up the search box to find the command, and then press Enter to run the command, which is convenient and quick.

The configuration is as follows:

Go to File–>Settings–>Tools–>External Tools

Configure the command and the working directory (where the command will run).

Shortcut Key Configuration

Proper configuration of shortcut keys can improve work efficiency.

The ones I use most are Project, Structure, Version Control, Terminal, Debug, so I reconfigured them to a more convenient ‘Alt+1/2/3/4/5’.

Write automated scripts to improve efficiency

In general, getting a patch file with a directory structure is cumbersome under Windows. To solve this problem efficiently, you can write your own shell script to solve it. For example, the following script:

#! /bin/bash
#The file name:doPatch
#File purpose: Package the patch file (including the directory structure) and upload it to the target hostEcho 'Start COMMIT_ID' read beginCommitId echo' End COMMIT_ID(default: HEAD)' read endId endCommitId=${endId:='HEAD'} echo 'PATCH_NAME(default: patch)' read name patchName=${name:='patch'} echo 'HOST_IP' read hostIp createTime= 'date "+%F-%H%M" patchPath='/home/hikwang/Downloads/tmp/patch/' fileName=$patchName'_'$createTime'.zip' zipFile=$patchPath$fileName
#Check whether the patch directory existsif [ ! -d "$patchPath" ]; then mkdir -p "$patchPath" fi if [[ $? -eq 0 ]]; Then # git diff - tree - r - no - commit - id - name - only $commitId | xargs "C: \ Program Files \ \ 7 - Zip 7 z" a $zipFile git diff - the name - only $beginCommitId $endCommitId | xargs "C: \ Program Files \ \ 7 - Zip 7 z" a $zipFile if [$? - eq 0]; $zipFile if [[$hostIp -ne null]]; then scp $zipFile 'root@'$hostIp':/home/' if [ $? -eq 0 ]; $fileName exit 0 else echo 'exit 1 fi else exit 0 fi else echo "Patch creation failed "; exit 1 fi fiCopy the code

To package the patch file, run the above script in PHPStorm’s Terminal and find the commit_id to use in phpStorm’s Version Control.

However, shell script files cannot be added to Windows environment variables (shell scripts cannot be added to Windows environment variables), so it is inconvenient to use the absolute path of the script file.

Git Bash can be used globally by placing a custom command in the same directory as the SCP command.

Find the directory where SCP is located. Mine is ‘L:\softwares\Git\usr\bin’ and place my script file ‘doPatch’ in that directory. Run doPatch directly under Git Bash and it works.