UNDO

Description

Undoes changes in a workspace.

Usage

cm undo [<path>[ ...]] [--symlink] [-r | --recursive] [<filter>[ ...]] [--silent | --machinereadable [--startlineseparator=<sep>] [--endlineseparator=<sep>] [--fieldseparator=<sep>]]

Options

Option / ArgumentDescription
--symlinkApplies the undo operation to the symlink and not to the target.
-rExecutes the undo recursively.
--silentDoes not show any output.
--machinereadableOutputs the result in an easy-to-parse format.
--startlineseparatorUsed with the '--machinereadable' flag, specifies how the lines should start.
--endlineseparatorUsed with the '--machinereadable' flag, specifies how the lines should end.
--fieldseparatorUsed with the '--machinereadable' flag, specifies how the fields should be separated.
pathPath of the files or directories to apply the operation to. Use double quotes (" ") to specify paths containing spaces. Use a whitespace to separate paths. If no path is specified, by default the undo operation will take all of the files in the current directory.
filterApplies the specified filter or filters to the given paths. Use a whitespace to separate filters. See the Filters section for more information.

Help

Remarks

  • If no path is specified, it will undo every change in the current directory but not recursively.
  • If one or more paths are specified, it will undo every change in the specified paths but not recursively.
  • If you want the operation to be recursive, you must specify the '-r' flag. To undo all of the changes below a directory including changes affecting the directory itself, run the following command:

cm undo dirpath -r

If dirpath is a workspace path, every change in the workspace will be undone.

  • The 'undo' command is dangerous because it undoes work irreversibly. Once the undo has finished, it is not possible to recover the previous state of the files and directories affected by it.
  • Consider the following scenario:
  • /src
    • file.txt
    • code.cs
    • /test
      • test_a.py
      • test_b.py

These commands are equivalent when executed from the /src directory

cm undo

cm undo *

cm undo file.txt code.cs /test

These commands are also equivalent when executed from the /src directory

cm undo .

cm undo /src file.txt code.cs

Filters

The paths can be filtered using one or more of the filters below. Each of those filters refers to a type of change:

Option / ArgumentDescription
--checkedoutSelects checked-out files and directories.
--unchangedSelects files whose content is unchanged.
--changedSelects locally changed or checked-out files and directories.
--deletedSelects deleted files and directories.
--movedSelects moved files and directories.
--addedSelects added files and directories.

If the path matches one or more of the specified kinds of changes, those types of changes will be undone on that said path. For example, if you specify both '--checkedout' and '--moved', if a file is both checkedout and moved, both changes will be undone.

If no filter is specified, all kinds of changes are undone.

Deleted items

To undo file and directory deletions, you must either specify the full path of the item, or specify the containing directory and use the recursive ('-r') flag.

For example

cm undo .

(Does NOT undo deletions (but other changes) in the current directory.)

cm undo . -r

(Undoes all deletions (and other changes) in the current directory recursively.)

cm undo src/file.txt

(Undoes deletion (or other change) of src/file.txt.)

Examples

cm undo . -r

(Undoes all changes in the current directory recursively. If executed from the workspace's root, undoes all changes in the entire workspace.)

cm co file.txt

cm undo file.txt

(Undoes the checkout on 'file.txt'.)

cm undo c:\otherworkspace\file.txt

(Undoes changes in file 'file.txt' located in a workspace other than the current one.)

echo content >> file.txt

cm undo file.txt

(Undoes the local change to 'file.txt'.)

cm undo src

(Undoes changes to the src directory and its files.)

cm undo src/*

(Undoes changes in every file and directory contained in src, without affecting src.)

cm undo *.cs

(Undoes changes to every file or directory that matches *.cs in the current directory.)

cm undo *.cs -r

(Undoes changes on every file or directory that matches *.cs in the current directory and every directory below it.)

cm co file1.txt file2.txt

echo content >> file1.txt

cm undo --unchanged

(Undoes the checkout of unchanged 'file2.txt', ignoring locally changed 'file1.txt'.)

echo content >> file1.txt echo content >> file2.txt

cm co file1.txt

cm undo --checkedout

(Undoes the changes in checked-out file 'file1.txt', ignoring 'file2.txt' as it is not checked-out.)

cm add file.txt

cm undo file.txt

(Undo the add of 'file.txt' making it once again a private file.)

rm file1.txt echo content >> file2.txt

cm add file3.txt

cm undo --deleted --added *

(Undoes the 'file1.txt' delete and 'file3.txt' add, ignoring the 'file2.txt' change.)