Tag Archive for 'command line'

Subversion Tip of the Week

Updating to a Particular Revision From the Command Line

When updating your working copy in Apache Subversion, you usually run the ‘SVN Update’ command and update to the HEAD revision. However, in some instances you may need to update your working copy to a particular revision – or even revert to a previous revision. This is achieved by running the ‘SVN Update’ command and specifying your target revision with the -r command:

svn update -r revision-number

You working copy will now be at the specified revision! In addition, there are several commands that you may find useful when targeting a particular, non-HEAD revision:

1) Find out which revision you’re currently at:

svn log -q -r BASE

2) Find out which revision is the HEAD:

svn log -q -r HEAD

3) See what’s changed between your working copy revision and HEAD:

svn log -r BASE:HEAD

Subversion Tip of the Week

Locking Files from the Subversion Command Line

Apache Subversion is built around the ‘copy-modify-merge’ model, but you can enforce a ‘lock-modify-unlock’ model if necessary. This can be useful when you’re editing files that cannot be easily merged, for example image files or large binary files.

Creating a Lock

To create a lock, use the ‘svn lock’ command followed by the location and name of the file you wish to lock:

svn lock (working-copy-path/filename)

Keep your colleagues in the loop by adding a log message explaining why you have locked the file. Log messages can be added using the -m switch:

svn lock (working-copy-path/filename) -m “log message”

In this example, we are locking an image file called ‘Logo’ with the log message “Working on logo.”

You can now make changes to the file on your local machine, confident that no one else is committing changes to the repository. Once you have finished modifying the file, you can unlock it using the ‘svn unlock’ command:

svn unlock (working-copy-path/filename)

In this example, we are unlocking the ‘Logo’ file from earlier:

Tip: when you commit back to the repository all locks are automatically released as part of the commit transaction. If you wish to commit without releasing any locks you can use the ‘–no-unlock’ switch to explicitly tell Subversion to maintain the locks:

svn commit –no-unlock (working-copy-path) -m “log message”

In this example we are committing to the repository without lifting the lock, and with the log message “initial draft of logo.”

Subversion Tip of the Week

Creating Changelists from the Command Line

In the world of modern software development, it’s not unusual for developers to be working on multiple, unrelated changes within the same project. In these situations, Apache Subversion‘s changelists can be an invaluable tool for keeping track of which changes relate to which part of the development effort.

Changelists are labels that can be used to group related files together. Files can be added to a changelist with the ‘svn changelist’ command, followed by the name of the changelist, and the file’s path:

svn changelist “Changelist-name” {path}

In this example, we are adding a text file called ‘Wiki’ to a changelist called ‘Changelist’:

You can add as many files as you want to each changelist, and can create multiple changelists within the same working copy. If you need to check on the status of your changelists, you can use the ‘svn status’ command, followed by the location of your working copy:

This will list all the files that are associated with the different changelists in your working copy.

Tip: There are some limitations worth baring in mind when using changelists:

    • Changelists cannot be sent to the repository, and therefore cannot be shared.
    • Changelists can only be assigned to files, and not directories.
    • Files can only be assigned to one changelist at a time.

 

Working with Files from the Subversion Command Line

While graphical clients such as TortoiseSVN are ever-popular with Apache Subversion users, it’s useful to have the option of interacting with Subversion from the command line. In the first of our introductory posts, we looked at checking out a working copy and committing your first changes back to the repository. In this follow-up tutorial, we focus on working with files in your local copy, and share some useful commands for getting all the information you need on your files and directories.

Adding Files in Subversion

Performing a checkout will create local copies of all the files in your repository, but at some point you may want to add completely new files or directories to your working copy. Once you have manually created or moved the file to your working copy, you must tell Subversion to include this file in its version control. This can be done by running the ‘svn add’ command and specifying where the new file is located in your working copy:

svn add {location}

For example, if you have just created a new text file called ‘howto’ in the trunk, you would enter the following command:

Hit ‘Enter,’ and the specified file will automatically be added to the repository when you perform your next commit.

Deleting Files in Subversion

If you can add files, then at some point you may need to delete them. To delete a file in your working copy, use the ‘svn delete’ command and specify the location of the file you wish to delete:

svn delete {location}{filename}

For example, if you wanted to remove the How To document we have just added, you would use the following command:

Do not delete files under version control using the Explorer menu, as Subversion will flag these files as ‘missing,’ and you will be unable to commit your changes until the deleted files have been restored.

Getting More Info

Now you know how to add and remove files from your working copy, we will cover the various commands that can be used to gather more information about your files, directories, working copy and repository.

  • To view the history of files in either the working copy or the repository, use the ‘svn log’ command, followed by either the repository URL or working copy location:
  • svn log {URL}
    svn log {location}

    For example, if you wanted to examine the history of the working copy, you would run:

    If the command is successful, you will see a dialog similar to the one below:

  • It is good practice to review your changes before committing them to the repository. This can be done by running ‘svn status,’ which will print the status of your working copy:
  • svn status {location}

  • At certain points during the development process, it may be useful to view a list of the repository, or working copy’s contents. This can be found using the ‘svn list’ command, and specifying either the repository’s URL or the working copy’s location:
  • svn list {URL}
    svn {location}

If you wanted to bring up a list of the repository’s contents, the command and dialog will look similar to this:

Getting Help

This post, together with our ‘Into to Command Line Subversion’ have covered the basic workcycle of interacting with Subversion from the command line – but there’s still plenty more to explore! If you need more information on what a particular command means, Subversion has ‘svn help’ which can be run, followed by the command in question:

svn help {command}

For example, if you needed more information on the ‘commit’ command, you would run:

Hit ‘Enter’ to display all the relevant information about the command.

Ready to get started with Subversion? Download free, certified binaries from WANdisco.

Intro to Command Line Subversion

While Subversion graphical clients such as TortoiseSVN are popular for quickly getting to grips with version control, it is also possible to interact with Subversion directly from the command line. Although graphical clients have their advantages, it is also useful to have the option of command line version control. In this post, we will cover the basics of command line Subversion by creating a repository, getting a working copy, and committing changes back to the repository.

SVN commands are entered via a terminal window. To open this in Windows, press the “Windows key” and “r.” Enter ‘cmd’ in the ‘Run Dialog box,’ and hit ‘OK.’

This will open the terminal.

To create your first repository, you must enter the ‘svnadmin create’ command, followed by the location where you wish to create the repository, and the name of the new repository:

svn admin create (location) (repository name)

In this example, we will create a repository called ‘Test’ in the Documents folder:

Hit ‘Enter’ and close the terminal window. You will notice that a new ‘Test’ folder has now been created in the Documents folder.

When you open this folder, you will see some new files.

The next step is to checkout a working copy. This is done using the ‘SVN Checkout’ command, followed by the URL of your repository, and the location you wish to copy your files to:

svn checkout (URL) (location)

Press ‘Enter.’ Now, when you check your local repository, you will see copies of all the files from your repository.

Now you are free to make changes to the files in your working copy. It is good practice to regularly update your working copy with any changes that have been made in the repository, to help avoid running into conflicts when you eventually commit your changes. An update is performed using the ‘svn update’ command, followed by the location of the working copy:

svn update (location)

Once you have finished working on the files, you can commit your changes to the repository. This is done using the ‘svn commit’ command, followed by the “–message” command and a log message explaining your changes, and finally, the location of your working copy:

svn commit –message “log message” (location)

Hit ‘Enter.’ If the commit is successful, you will see a dialog similar to the one below:

Your changes have now been successfully committed to the repository!

Subversion Tip of the Week

Command Line Quickstart

Apache Subversion has no shortage of useful GUI clients, but it’s also useful to know how to interact with Subversion from the command line. Here’s our five-step guide to getting started with command line Subversion in Windows!

1) Subversion commands are entered via a terminal window. To open this in Windows, press the ‘Windows key’ and ‘r.’ This will bring up the ‘Run’ dialog box. Enter ‘cmd’ and hit ‘Ok.’

2) To create your first repository, run the following command:

svnadmin create {location where you wish to create your working copy} {working copy name}

3) Now you have created your repository, the next step is to checkout a working copy. This is done with the following command:

svn checkout {repository URL} {working copy location}

4) Now you have a local working copy on your machine. Edit away!

5) When you are ready to commit your changes back to the repository, run the ‘svn commit’ command followed by “–message” and an appropriate log message, and finally, the location of your working copy.

svn commit “–message” {log message} {working copy location}

Your changes have now been committed to the repository!