How can I reset an edited history line in Bash?

Undo is C-x C-u (or C-_, for which you may have to type C-/)


The file that contains the bash history is "~/.bash_history", fittingly enough(at least in ubuntu, might be different in other flavors). just open it with your favorite text editor, note that each user should have their own .bash_history file. Also note that the preceding "." means that it is a hidden file, so it will not show up in a file browser or with the ls command unless you use it with -a.


This binding will prevent un-executed history alterations from over-writing the originals:

bind 'set revert-all-at-newline on'

Example:

  1. Execute ls
  2. Press up arrow
  3. Add -Al to the line
  4. Press down arrow
  5. Press Return (to try to cancel the change)

Without this binding:
ls will be replaced in history by ls -Al, even though it was never executed.

With this binding:
The un-executed ls -Al will disappear, whilst ls remains.

Obviously this means that un-executed history alterations will never be saved (like zsh's default behaviour). If you only want the originals restored sometimes, you'll have to go with one of the other answers.