Undo belongs to the selected buffer. Finish prompts and leave special menus, check the buffer with C-e m, and press C-g in ordinary text to deactivate any selection before undoing across the buffer. An active region can limit undo to that region.
Use M-x undo-only RET to undo one recorded change, then inspect with C-e l or a freshly selected short region. Deactivate that inspection region before the next undo. Repeat only as far as necessary. Insertion and deletion can occupy separate undo records; a multi-step move can therefore need more than one correction.
C-/ is the familiar undo key and works for an initial undo. However, an
intervening reading or movement command breaks its undo sequence, and a later
ordinary undo can redo what you just undid. undo-only avoids that reversal
when you pause to inspect through speech. M-x undo-redo RET deliberately
reapplies undone changes when the buffer’s undo history permits it.
For an accidental transfer between buffers, undo the insertion at the destination and the cut at the source separately, inspecting each. Copying needs no source undo because it left the source unchanged. Neither operation writes a file until you save. Correcting a saved edit changes the buffer again; save the verified correction explicitly if the file on disk must change too. Do not use Revert or close an unsaved buffer as a substitute for inspecting it.
The GNU Emacs Manual’s Undo section explains history, selective undo and limits. For file destinations and save failures, see Save a separate working copy. Text undo does not reverse a settings-menu save, a filesystem operation or an action already sent to a terminal.