UNDO
Undo changes with the Unity Version Control CLI.
Read time 3 minutesLast updated 21 days ago
Description
Undoes changes in a workspace.Usage
cm undo [<path>[ ...]] [--symlink] [-r | --recursive] [<filter>[ ...]] [--silent | --machinereadable [--startlineseparator=<sep>] [--endlineseparator=<sep>] [--fieldseparator=<sep>]]
Options
Option / Argument | Description |
|---|---|
| --symlink | Applies the undo operation to the symlink and not to the target. |
| -r | Executes the undo recursively. |
| --silent | Does not show any output. |
| --machinereadable | Outputs the result in an easy-to-parse format. |
| --startlineseparator | Used with the '--machinereadable' flag, specifies how the lines should start. |
| --endlineseparator | Used with the '--machinereadable' flag, specifies how the lines should end. |
| --fieldseparator | Used with the '--machinereadable' flag, specifies how the fields should be separated. |
| path | Path 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. |
| filter | Applies 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:
If dirpath is a workspace path, every change in the workspace will be undone.cm undo dirpath -r
- 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 / Argument | Description |
|---|---|
| --checkedout | Selects checked-out files and directories. |
| --unchanged | Selects files whose content is unchanged. |
| --changed | Selects locally changed or checked-out files and directories. |
| --deleted | Selects deleted files and directories. |
| --moved | Selects moved files and directories. |
| --added | Selects added files and directories. |
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
(Does NOT undo deletions (but other changes) in the current directory.)cm undo .
(Undoes all deletions (and other changes) in the current directory recursively.)cm undo . -r
(Undoes deletion (or other change) of src/file.txt.)cm undo src/file.txt
Examples
(Undoes all changes in the current directory recursively. If executed from the workspace's root, undoes all changes in the entire workspace.)cm undo . -r
cm co file.txt
(Undoes the checkout on 'file.txt'.)cm undo file.txt
(Undoes changes in file 'file.txt' located in a workspace other than the current one.) echo content >> file.txtcm undo c:\otherworkspace\file.txt
(Undoes the local change to 'file.txt'.)cm undo file.txt
(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 src/*
(Undoes changes to every file or directory that matches *.cs in the current directory.)cm undo *.cs
(Undoes changes on every file or directory that matches *.cs in the current directory and every directory below it.)cm undo *.cs -r
echo content >> file1.txtcm co file1.txt file2.txt
(Undoes the checkout of unchanged 'file2.txt', ignoring locally changed 'file1.txt'.) echo content >> file1.txt echo content >> file2.txtcm undo --unchanged
cm co file1.txt
(Undoes the changes in checked-out file 'file1.txt', ignoring 'file2.txt' as it is not checked-out.)cm undo --checkedout
cm add file.txt
(Undo the add of 'file.txt' making it once again a private file.) rm file1.txt echo content >> file2.txtcm undo file.txt
cm add file3.txt
(Undoes the 'file1.txt' delete and 'file3.txt' add, ignoring the 'file2.txt' change.)cm undo --deleted --added *