Tag Archive for 'revert'

Getting More out of Version Control with SmartSVN

In our previous SmartSVN posts, we covered essential functionality to get you off to a flying start with this cross-platform graphical client for Apache Subversion. In this post, we cover some more advanced options, including performing a reverse merge, reverting local changes and resolving any conflicts that occur when you try to perform a commit with SmartSVN.

Didn’t catch our intro to SmartSVN series? Get up to speed with the following links:

Reverse Merge

As Subversion remembers every change that’s committed to the repository, it’s possible to revert to previous revisions of your project. This is useful if you introduce a code-breaking feature in revision 15, and need to revert to a revision before it all went wrong. This is achieved by performing a ‘reverse merge’ i.e merging the changes in your current revision, to an earlier revision.

To perform a reverse merge with SmartSVN:

1) Select the ‘Merge’ item from the ‘Modify’ menu.

2) In the Merge dialog, enter the revision number you wish to roll back to.

 

 

 

 

 

 

 

If you need more information about the different revisions, click the ‘Select…’ button next to the ‘Revision Range’ textbox. The subsequent dialog displays the different revisions, alongside the commit message, time, author and path data for each revision. Note, the green arrows indicate revisions not yet merged.

 

 

 

 

 

 

 

3) Ensure the ‘Reverse merge’ checkbox is selected and finally, click ‘Merge.’

4) Remember to commit your changes to the repository, to make this reverse merge permanent!

Alternatively, right-click the revision you wish to reverse-merge in the Transactions tool window and select “Rollback.”

Revert

Revert overwrites any local changes made to the working copy, with the file content held in the repository. Note, this command should be used with caution: a revert effectively deletes all the changes made since your last commit, and once they are gone there is no way to recover them.

To perform a revert with SmartSVN, right-click on the file/directory you wish to revert, and select the ‘Revert’ option from the drop-down menu  (alternatively, select the ‘revert’ button from the toolbar.)

 

 

 

 

 

 

 

SmartSVN will ask you to confirm the revert. Select the ‘Revert’ button to go ahead and remove all your local changes.

 

 

 

 

Relocate

At some point during your project’s lifecycle, your repository may change location and therefore get a new URL. This can be solved by deleting your working copy and performing a checkout from the new repository location, but there is a quicker way to solve this problem: the ‘Relocate’ command can be used to rewrite all the URLs associated with the files and folders in your working copy, with the new URLs. This allows you to continue using your current working copy and, of course, to successfully commit all your hard work back to the repository.

1) Open the ‘Modify’ menu and select ‘Relocate…’

2) The ‘Relocate’ dialog displays the URL of the selected directory. In the ‘To URL’ option, specify the replacement URL.

 

 

 

 

 

 

3) Select ‘Relocate’ to change the repository for your directory.

Note, this operation should be used with caution, as if used incorrectly it can corrupt your working copy. The ‘Relocate’ command should not be used to:

  • move to a different Subversion repository.
  • switch to a different branch or directory within the same repository.

Resolving Conflicts

When you are performing a commit in Apache Subversion, you may occasionally encounter the dreaded Subversion conflict, and your commit will fail. Thankfully, SmartSVN comes with a ‘conflict solver’ to help resolve these conflicts when they do occur. To access this conflict solver, open the ‘Query’ menu and select ‘Conflict solver.’

 

 

 

 

 

 

 

 

 

 

In the ‘Mark Resolved’ dialog, you can opt to:

  • Leave the file/directory as it is.
  • Take the version in the working copy, as it was before the update or merge was performed.
  • Take the new version – the pristine copy after the update or merge was performed.
  • Take the old version – the pristine copy before the update or merge was performed.
Select the appropriate checkbox and select ‘Ok.’ The conflict should now be resolved, and you can commit your changes to the repository to make them permanent.
Set a Property
‘Properties’ in Subversion are useful for associating metadata with the files placed under version control. To set a property for your Subversion files or directories using SmartSVN, open the ‘Properties’ menu and click ‘Select or delete Property….’
Use the drop-down ‘Property’ menu to select the desired Subversion internal property. The default properties are:
  • svn:eol-style – makes the client convert line-endings in text files. This property is used when the working copy is required in a specific EOL style.
  • svn:executable – makes files on Unix-hosted working copies executable.
  • svn:externals – a multi-line value defined on a directory that allows parts of other repositories to be automatically checked out.
  • svn:ignore – a list of unversioned filename patterns that should be ignored by ‘svn status’ and other subcommands.
  • svn:keywords – Subversion has the ability to substitute keywords into the contents of a file itself when changes are made. Keywords are useful for automatically maintaining information (such as author, revision number, etc) that would be too time-consuming to keep changing by hand.
  • svn:mergeinfo – this property is used to track merge data and is automatically maintained by the ‘SVN merge’ command.
  • svn:mime-type – indicates the file’s MIME type and allows the client to decide if contextual merging is safe during updates. Note, this property affects the handling of diffs and merging.
  • svn:needs-lock – tells the client that files should be checked out with permissions set to read-only. This is designed to be used in conjunction with the ‘SVN Lock’ command, to remind the developer to obtain a lock before beginning work on a file. This saves the developer from spending time modifying a file and then discovering it’s locked when it’s time to commit.

Select a value for your property (if applicable) and hit the ‘Ok’ button to set the new property.

Visit http://smartsvn.com/ to claim your free download of SmartSVN Foundation.

Subversion Tip of the Week

Revert to a previous revision

As Apache Subversion remembers every change made to its files and directories, it is always possible to roll back to a previous version of your project. This can be a life-saver if new features have turned out to be unnecessary, or even introduced bugs into your project. Simply rolling back to a revision before it all went wrong, can be far quicker and easier than trying to fix all of the problems manually.

Reverting to a previous revision in Subversion, is simply a matter of merging the changes in your current revision, to an earlier revision. To get started with reverting to a previous revision, select ‘Merge’ from the TortoiseSVN menu.

Select ‘merge a range of revisions.’ Click ‘Next.’

Select ‘Show Log.’

Select the revision you wish to roll back to. In this instance, we’ll revert to revision 13.

The selected revision will be automatically entered into the ‘Merge’ dialog. Ensure ‘Reverse merge’ is selected, and click ‘Next.’

This dialog allows you to set a range of options for merging. However, in most instances the default settings can be used. Click ‘Merge.’

Subversion will now roll your working copy back to revision 13.

Tip: Remember that the merge command only changes files in the working copy, so you must remember to commit your changes back to the repository.

Our Support Engineers are the Sherpas of Source Control Management! Just as traditional Sherpas use their deep knowledge of local terrain to assist mountain climbers in reaching the highest peaks and avoiding pitfalls along the way, WANdisco’s Subversion Sherpas use their extensive experience to guide customers away from problems and enable them to get the most out of Subversion. Our ‘Team Sherpa’ consists of highly skilled support engineers and core Subversion developers who have been working on the Subversion project since it began, and are also uniquely positioned to help you migrate to the latest and greatest releases of SVN. You can hire one of our Subversion Sherpas today, by visiting http://www.wandisco.com/subversion/support

Subversion Tip of the Week

The Undo Button!

In the world of software development, client requirements change and new features can introduce more bugs than they fix – sometimes, you just need an ‘undo’ button! Thankfully, Apache Subversion remembers every change made to its files and directories, so you can roll back to a revision before it all went wrong! There are several methods for reverting to a previous version:

1) svn revert {filename} – this command overrides any local changes made to the working copy, with the code in the repository.

To run this command in TortoiseSVN, select ‘Revert…’ from the TortoiseSVN menu.

You will then be able to specify which changes you wish to implement. In this example, we are re-adding the ‘Help file.’

2) svn merge -r {revision number} – this command performs a reverse merge by rolling back to a change that has already been committed to the repository, and then applying it to the local working copy.
3) Alternatively, it is possible to simply delete your working copy and then checkout a fresh working copy from the repository.

Subversion Tip of the Week

Subversion Insider Tips

So, you’ve got to grips with using Subversion in your day-to-day development; you’ve read up on best practices, and even branching and merging is no longer giving you nightmares – but are you taking full advantage of everything Subversion has to offer? In this post, we look at some useful, but frequently overlooked, Subversion features.

Revert Command

The Subversion repository remembers every change that’s made to the files and directories, which is useful when reviewing the history of changes made within your project, but it also allows users to recover older versions of their code.

The ‘svn revert’ command can be used to overwrite any local changes made to the working copy, with the code held in the repository. This includes any property changes, and any scheduling operations that may have been set on the working copy. Note that the revert command replaces all changes made to your working copy – once they are gone, there is no way to recover them; you will lose all the changes made since the last commit.

Reverse Merge

A reverse merge rolls back a change that has already been committed to the repository, and then applies it to the local working copy. A reverse merge can be performed with the following commands:

1) svn merge –dry-run – (optional) displays what the merge will produce.
2) svn merge -r (revision number) – rolls the working copy back to the specified revision. Note that a reverse merge is like any other merge operation, so ‘svn status’ and ‘svn diff’ can be used to inspect and approve the changes.
3) svn commit – the merge command will only change files in the working copy, so remember to commit the changes to the repository.

External Files and Folders

Occasionally, it’s useful to construct a working copy that consists of several different checkouts. To help with this, Subversion supports external definitions, which allow users to map a local directory to the URL of a versioned resource. External definitions are declared with the ‘svn:externals’ property.

Once ‘svn externals’ is set on a versioned directory, everyone who checks out a working copy from that directory, also checks out the definitions, so only one person needs to define the nested working copy checkout per repository.

To edit the externals definition, use the following subcommand:

svn propedit (target)

When anyone runs ‘svn update,’ Subversion will automatically synchronize the checked out items against the changed externals definition. Similarly, when other team members update their working copy, they will automatically receive any changes made to the externals definition.

The ‘svn status’ command can be used to print the status of working copies and directories with ‘svn:externals’ properties, as ‘svn status’ recognizes externals definitions.

Subversion Tip of the Week

The Oops Command

Often when you are changing code, you will realize that you have meandered down the wrong coding path. You can take the manual approach and try to back out of your changes but Apache Subversion gives us an easier way. It is called the revert command.

If you want to have a file restored to where it was when you last checked it out, or when it was last updated, you can use the revert command to restore a file (or files). This command will appear in the context menu from your working folder if any files have been changed. Be aware that if you select a changed file and then right-click, you will only be reverting that file (or files) you have selected. To make sure you will be affecting all the files that have been modified, either right click on the top of the working folder or make sure you have selected (using the Ctrl/Key) all the files you may want to convert.

Below is an example of the first step of the revert command. Here you can decide which files to revert and which to ignore.

You can check the box of any file you may want to revert to what it looked like when it was checked out or updated. Be aware that both a files’ changes and any changed Subversion properties will be changed by the revert command.

At the bottom of the form there is a button labeled “Delete unversioned items…” This will present you with a form where any files that you have added since doing a checkout (but not added with the Subversion ADD Command) can be selected, and then deleted.

The revert command also works with folder changes. Below you see the effect of running the revert command after adding a new folder (“newfolder”) and renaming a folder (“reports” was renamed to “User_reports_renamed”).

The effect of a rename shows up as the deletion of the old folders and addition of the new (renamed) folder.

Every week WANdisco’s Head of Training Mike Lester will publish a tip to help you get the most out of Apache Subversion. Mike also delivers free, bi-weekly training webinars on topics ranging from branching and merging best practices, to Subversion in the enterprise, and advice on making Subversion agile. Register early, to avoid missing out! Enterprise Training is also available.