Committing changes to a Subversion repository
During the course of a project, plugin files will typically be created, modified, or deleted. These changes should be transmitted regularly to the Subversion repository to have proper backups of all the files in a project. A good practice is to commit changes at least once a day, with more frequent commit operations taking place when specific milestones are reached in the implementation of a plugin's features.
This recipe indicates how to manage file creation, modification, and deletion operations to keep everything organized and mirrored in the Subversion repository.
Getting ready
You should have already installed a Subversion client, created a local repository, and imported and checked out files before performing the steps in this recipe. These steps will be slightly different based on the Subversion client that you have selected and the operating system you are using.
How to do it...
- Navigate to the WordPress plugin directory of your local installation in the file explorer if you are not already there.
- Open the
hello.php
file in a text editor. - Edit the plugin name on line 7 to change it from
Plugin Name: Hello Dolly
toPlugin Name: Goodbye Dolly
. - Save and close the file. You should now notice that the modified file is identified by a red exclamation mark icon in the file explorer, indicating that it has been modified.
- Create a new folder in the
plugins
directory namedchapter1
. - Right-click on the new folder and select the
TortoiseSVN | Add...
menu item to bring up theAdd
dialog. - Click on the
OK
button to queue the file to be added to the repository when changes are next committed. You will see a blue plus sign appear over the folder name to indicate that it will be added to the repository on the next code commit. - Navigate to the
chapter1
directory and create a new text document namedexample.txt
. - Navigate back to the
plugins
directory. - Right-click on the
index.php
file and select theTortoiseSVN | Delete
menu item. The selected file is immediately deleted and disappears from the file explorer.
- Right-click in an empty part of the
plugins
directory and select theSVN Commit...
menu item. This last step will display theCommit
dialog, with a top section to write a message detailing the changes that are being committed, and a bottom section containing a file listing. Notice that all files but one have check marks next to them, since they have either been recognized as being changed by the Subversion client or have been added or deleted through the TortoiseSVN interface. The file that does not have a check mark next to it is the text file that was created but not tagged to be included in the next commit operation using the TortoiseSVN contextual menu:

- Type a message in the appropriate field indicating the reason for the operation.
- Right-click on the
chapter1/example.txt
file and select theAdd
menu item to add it to the operation. - Click on the
OK
button to send all the changes to the Subversion repository.
How it works...
Using the local data stored in the .svn
folder, the Subversion client is able to analyze the directory contents and identify all the files that are new, have been modified, or are missing since the last checkout or update operation was performed, and then generate a list of these changes.
When the commit operation is performed, new files are added to the repository, modified files are uploaded and stored next to their previous versions, while deleted files are tagged as no longer being part of the current project version. While some of these behaviors might seem strange, it's by preserving previous versions of files and even keeping files that are no longer part of a project that Subversion is able to let us navigate through a project's entire history.
While it is preferable to use the TortoiseSVN menu to mark files and directories for addition and to delete items that are no longer needed, it is also possible to perform these operations when the commit is about to take place, as we saw in the recipe steps.
There's more...
Before files are committed to the repository, many programmers and developers want to see what changes were made to the modified files, especially in an environment that promotes peer reviews before committing code changes.
Viewing the differences in modified files
By right-clicking on any modified file in the Commit dialog and selecting the Diff
menu item, the TortoiseSVN client will display its built-in file difference viewer tool, highlighting the parts that are different between the last version of the file in the repository and the current version of this file. This allows users to see what changed at a glance and be sure that no code was modified inadvertently.
Updating files to latest repository version
If you are the only person committing files to a repository and you are working on a single computer, then you will never need to use the SVN Update
menu item. This function is designed to compare your local files with the repository and check if new files or new revisions are available in the repository that are not present locally. It will then apply all the necessary changes to the local versions of these files. Remember to use the SVN Update
option in TortoiseSVN regularly if you are working in a team environment or are developing a project across multiple computers.
Reverting uncommitted file changes
Until a file is committed to a repository, it's possible to reverse all the changes made to it since the last checkout, update, or committal by using the Revert
item in the TortoiseSVN
menu. This can be useful if you made changes to the code that broke its functionality and want to get back to a known good state.
Viewing file history
As multiple versions of files are committed to a repository over time, Subversion keeps track of all the versions of these files along with the messages that were associated with each commit operation. The Show Log
tool, accessible from the TortoiseSVN menu, allows you to see a full history of changes made to one more files, use the difference viewer to see changes between previous and current versions of each file, and easily restore a specific revision of these files.