Bash – How to prevent edited commands from overwriting the original? Or revert edits

bashcommand history

Often I'll execute a command in bash, press the up arrow to retrieve it from history, edit it, and execute the edit. However, sometimes I'll decide to discard the edit and run a different command or something. This poses a problem because the edited command, which I didn't run, gets saved over top of the original history entry so I can no longer run the original with ease.

For example, here's the end of my current history:

2132* svn cleanup && svn up --set-de
2133  history

The first command was originally svn cleanup && svn up --set-depth=infinity folder1 folder2.

Is there a way to disable overwrites or revert them to the original commands?

Best Answer

Abort the line editing with ctrl+c instead of deleting the command, that way bash doesn't overwrite the history line.

Related Question