Snapshots

Snapshots allow you to save project state at particular points in time, which you can restore entirely or partially at a later point. Snapshots provide a multifile undo/redo mechanism that lets you experiment freely with your source files. A snapshot stores the state of a directory tree at the time it was taken. The changes you make can be easily reverted by restoring your project to a snapshot you made before the experiment.

At any particular time, a project can access only one snapshot store. A snapshot store is the set of snapshots taken from one or more projects with the same project root. (See General Project Attributes to learn how to set a project’s project root.)

Xcode stores snapshots in your home directory:

~/Library/Application Support/Developer/Shared/SnapshotRepository.sparseimage

This chapter shows how to use locally stored snapshots to manage changes to multiple files.

The Snapshots Window

The Snapshots window (Figure 3-1) is where you view your project’s snapshots.

Figure 3-1  The Snapshots window

The Snapshots window contains the following items:

Making Snapshots

To make a snapshot, choose File > Make Snapshot.

You may want to change the snapshot name to reflect special circumstances.

To change the name of a snapshot, select the snapshot in the Snapshots list, and enter the new name in the Name field.

Comparing Snapshots

When you select a snapshot in the Snapshot window, the changed file list shows the differences between the snapshot and the current state of the project. That is, Xcode compares the snapshot against the project.

Sometimes you may need to know what changed between two snapshots. You can view the differences between two snapshots by selecting them in the Snapshot list.

Restoring Snapshots

To restore the project to the state represented by a particular snapshot, select the snapshot in the Snapshot list, and click Restore.

To restore a single file in a snapshot:

  1. In the Snapshot list, select the desired snapshot.

  2. In the file list, select the file to restore, and click Restore.

  3. Click the Restore button.

To restore a single change instead of an entire file:

  1. In the Snapshot list, select the desired snapshot.

  2. In the file list, select the desired file.

  3. In the changes pane, copy the text to restore.

  4. Open the file into which you want to restore the copied text.

  5. Paste the text in the appropriate location, and save the file.

Deleting Snapshots

From time to time, you may want to prune a snapshot store. You can do this by deleting individual snapshots or deleting the snapshot store.

To delete a snapshot, In the Snapshots window, select the snapshot you want to delete, and click Delete in the toolbar.

To delete a snapshot store, first Quit Xcode. Then in the Finder, navigate to the directory that contains the snapshot store (see Snapshots for details), and delete the SnapshotRepository.sparseimage file.