Undo is an interaction technique which is implemented in many computer programs. It erases the last change done to the document, reverting it to an older state. In some more advanced programs, such as graphic processing, undo will negate the last command done to the file being edited. With the possibility of undo, users can explore and work without fear of making mistakes, because they can easily be undone.

The expectations for undo are easy to understand: to have a predictable functionality, and to include all "undoable" commands. Usually undo is available until the user undoes all executed operations. But there are some actions which are not stored in the undo list, and thus they cannot be undone. For example, save file is not undoable, but is queued in the list to show that it was executed. Another action which is usually not stored, and thus not undoable, is scrolling or selection.

The opposite of to undo is to redo. The redo command reverses the undo or advances the buffer to a more recent state.

The common components of undo functionality are the commands which were executed of the user, the history buffer(s) which stores the completed actions, the undo/redo manager for controlling the history buffer, and the user interface for interacting with the user.

In most graphical applications for the majority of the mainstream operating systems (such as Microsoft Windows, Linux and BSDs), the keyboard shortcut for the undo command is Ctrl+Z or Alt+Backspace, and the shortcut for redo is Ctrl+Y or Ctrl+Shift+Z. In most macOS applications, the shortcut for the undo command is Command-Z, and the shortcut for redo is Command-Shift-Z. On all platforms, the undo/redo functions can also be accessed via the Edit menu.

History

The ability to undo an operation on a computer was independently invented multiple times, in response to how people used computers.

The File Retrieval and Editing System, developed starting in 1968 at Brown University, is reported to be the first computer-based system to have had an "undo" feature.

Warren Teitelman developed a Programmer's Assistant as part of BBN-LISP with an Undo function, by 1971.

Marvin Zelkowitz proposed in his PhD thesis (Reversible Execution as a Diagnostic Tool) in 1971 at Cornell University the concept of reversible execution, which is essentially an undo. In his PhD thesis (An Interactive Analysis System for Execution-Time Errors) at the University of Illinois at Urbana-Champaign in 1975, Alan M. Davis expanded on Zelkowitz's concept to show how multi-level undo (i.e., multi-level reversible execution) could be used for debugging software programs.

The Xerox PARC Bravo text editor had an Undo command in 1974.

A 1976 research report by Lance A. Miller and John C. Thomas of IBM, Behavioral Issues in the Use of Interactive Systems, noted that "it would be quite useful to permit users to 'take back' at least the immediately preceding command (by issuing some special 'undo' command)." The programmers at the Xerox PARC research center assigned the keyboard shortcut Ctrl-Z to the undo command, which became a crucial feature of text editors and word processors in the personal computer era. In 1980, Larry Tesler of Xerox PARC began working at Apple Computer. There, he and Bill Atkinson advocated for the presence of an undo command as a standard fixture on the Apple Lisa. Atkinson was able to convince the individual developers of the Lisa's application software to include a single level of undo and redo, but was unsuccessful in lobbying for multiple levels. When Apple introduced the Lisa's successor, the Macintosh, it stipulated that all standard applications should include an “Undo” as the first command in the “Edit” menu, which has remained the standard on macOS and Windows to this day.

Multi-level undo commands were introduced in the 1980s, allowing the users to take back a series of actions, not just the most recent one. This was the standard model prior to the widespread adoption of multiple-level undo in the early 1990s.

Undo implementation

Undo can be implemented through different patterns. The most common patterns are command pattern and memento pattern.

Command pattern

The command pattern is a software design pattern which encapsulates information from the operation into command objects. This means that every action is stored in an object. The abstract command class implements an abstract execute operation, so every command object has an execute operation. For undo there also have to be unexecuted operation, which undoes the effect of the executed command, which are stored in a history list. Undo and redo are implemented so that the list is run through forwards and backwards when the execute or unexecute command is called.

For single undo only the executed command is stored. In contrast to the multi level undo where not only the history list with the commands is saved but also the number of undo levels can be determined of the maximum length of the list.